最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

“错误TS2304:使用Google api库编译打字稿时找不到名称'Long'”

运维笔记admin9浏览0评论

“错误TS2304:使用Google api库编译打字稿时找不到名称'Long'”

“错误TS2304:使用Google api库编译打字稿时找不到名称'Long'”

我刚刚在pacakge.json中添加了"@google-cloud/logging-winston":"2.1.0",,并且在编译时出现以下错误。我偶尔在其他Google库中也看到过这种情况,其根本原因很可能是来自protobuf定义的自动生成的类型在堆栈中更深。

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1434:32 - error TS2304: Cannot find name 'Long'.

1434                 line?: (number|Long|null);
                                    ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1453:38 - error TS2304: Cannot find name 'Long'.

1453                 public line: (number|Long);
                                          ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1543:39 - error TS2304: Cannot find name 'Long'.

1543                 requestSize?: (number|Long|null);
                                           ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1549:40 - error TS2304: Cannot find name 'Long'.

1549                 responseSize?: (number|Long|null);
                                            ~~~~

../node_modules/@google-cloud/logging/build/proto/logging.d.ts:1576:42 - error TS2304: Cannot find name 'Long'.

1576                 cacheFillBytes?: (number|Long|null);

回答如下:

在解决此问题之前,我是如何解决此问题的。

  1. 在您的package.json依赖项部分中,添加"long":"4.0.0",
  2. 在您的package.json devDependDependence部分:添加"@types/long":"4.0.0",
  3. 最后,在tsconfig.json中(或在tsc命令行中添加:
{
   "compilerOptions": {
     ...
     "types": [
       ...
       "long"
     ],
   ...
}
发布评论

评论列表(0)

  1. 暂无评论