[英]"error TS2304: Cannot find name 'Long'" when compiling typescript with google api libraries
我剛剛在我的 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);
以下是我如何解決這個問題,直到它得到處理。
"long":"4.0.0",
"@types/long":"4.0.0",
{
"compilerOptions": {
...
"types": [
...
"long"
],
...
}
gae123 建議在 typescript 版本 4.9.4 上對我不起作用。 我將以下內容添加到 tsconfig.json。 希望這可以幫助。
"compilerOptions":{
...
"skipLibCheck": true,
}
我解決了添加long
數據包和@types/long
問題,正如 gae123 建議的那樣,但現在類型不是添加到tsconfig.json
而是添加到tsconfig.app.json
中。
"compilerOptions": {
...
"types": [...,"long"]
}
謝謝gae123!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.