我刚刚在我的 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);
最佳答案
以下是我如何解决此问题直至问题得到解决的方法。
- 在 package.json 依赖项部分添加
"long":"4.0.0",
- 在 package.json devDependencies 部分中:添加
"@types/long":"4.0.0",
- 最后,在 tsconfig.json 中(如果不起作用,请添加到 tsconfig.app.js)(或在 tsc 命令行中)添加:
{
"compilerOptions": {
...
"types": [
...
"long"
],
...
}
关于node.js - 使用 google api 库编译 typescript 时 "error TS2304: Cannot find name ' Long '",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58159115/