首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Typescript Google API编译错误

Typescript Google API编译错误
EN

Stack Overflow用户
提问于 2019-02-23 04:34:30
回答 1查看 1.6K关注 0票数 6

我正在使用Typescript,tslint和Google APIs,但在将typescript编译成javascript时出现了问题,我不确定为什么,出于某种原因,我在网上找不到任何关于这个问题的具体信息。谷歌搜索并没有提供好的结果。我也找不到一个很好的例子来说明应该如何使用这个库来设置tsconfig。所以我要来这里。

当我运行tsc时,我遇到了很多“找不到类型定义文件”和“找不到模块”的错误。

我的文件实际上就是这一行:

import {google} from 'googleapis'

就这样。

当我运行tsc时,它给出了以下错误:

代码语言:javascript
复制
$ tsc
node_modules/gaxios/build/src/common.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.

1 /// <reference types="node" />
                        ~~~~

node_modules/gaxios/build/src/common.d.ts:3:23 - error TS2307: Cannot find module 'https'.

3 import { Agent } from 'https';
                        ~~~~~~~

node_modules/google-auth-library/build/src/auth/authclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/authclient.d.ts:17:30 - error TS2307: Cannot find module 'events'.

17 import { EventEmitter } from 'events';
                                ~~~~~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:17:21 - error TS2307: Cannot find module 'fs'.

17 import * as fs from 'fs';
                       ~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:19:25 - error TS2307: Cannot find module 'stream'.

19 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/googleauth.d.ts:182:20 - error TS2503: Cannot find namespace 'NodeJS'.

182     _osPlatform(): NodeJS.Platform;
                       ~~~~~~

node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:17:25 - error TS2307: Cannot find module 'stream'.

17 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:18:25 - error TS2307: Cannot find module 'stream'.

18 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:17:25 - error TS2307: Cannot find module 'stream'.

17 import * as stream from 'stream';
                           ~~~~~~~~

node_modules/google-auth-library/build/src/crypto/crypto.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.

16 /// <reference types="node" />
                         ~~~~

node_modules/google-auth-library/build/src/crypto/crypto.d.ts:32:60 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node` and then add `node` to the types field in your tsconfig.

32     verify(pubkey: string | JwkCertificate, data: string | Buffer, signature: string): Promise<boolean>;

我的tsconfig文件是:

代码语言:javascript
复制
    {
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "esModuleInterop": true,
    "noImplicitAny": false,
    "moduleResolution": "node",
    "sourceMap": true,
    "outDir": "app",
    "baseUrl": "./app",
    "paths": {
      "*": [
        "node_modules/*"
      ]
    }
  },
  "include": [
    "src/**/*"
  ]
}

我的包依赖项是:

代码语言:javascript
复制
  "dependencies": {
    "googleapis": "^37.2.0",
    "mysql": "^2.16.0",
    "typescript": "^3.3.3333"
  },
  "devDependencies": {
    "nodemon": "^1.18.10",
    "tslint": "^5.12.1"
  }

我使用的不是tsc节点模块(已弃用),我使用的是typescript v3.3.3

感谢您的帮助!:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-23 04:58:39

第三方库中的类型错误可以通过提交一个拉取请求或在您的tsconfig中打开skipLibCheck: true并等待它们被修复来轻松避免。

希望这能有所帮助。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54834784

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档