【问题标题】:"error TS2304: Cannot find name 'Long'" when compiling typescript with google api libraries使用 google api 库编译打字稿时出现“错误 TS2304:找不到名称‘Long’”
【发布时间】:2020-01-29 05:31:34
【问题描述】:

我刚刚在我的 pacakge.json 中添加了"@google-cloud/logging-winston":"2.1.0",,当我编译时出现以下错误。我偶尔会在其他谷歌库中看到这一点,其根本原因很可能是在从 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);

【问题讨论】:

    标签: node.js typescript google-cloud-platform google-api


    【解决方案1】:

    这是我在解决此问题之前的解决方法。

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

    【讨论】:

    • 这行得通。有官方修复之类的吗?谢谢!
    • 我不知道,根据我读到的内容,我得出的结论是,Google Cloud 节点库团队会迅速为他们的模块跳转到最新的 typescript 编译器,而没有考虑对使用旧模块的用户的影响Typescript 编译器的版本。希望,只要您继续升级您的 Typescript 编译器,问题就会消失。希望他们对这些问题变得更加敏感。
    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 2019-02-13
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多