我有一個托管在 Firebase 中的現有 webapp 專案,我想向其中添加云功能。但是,當我僅使用該命令運行時firebase init functions,由于 gRPC 節點模塊中的錯誤,它生成的初始 hello-world 模板無法在 TypeScript 中編譯。
我的檔案夾結構:
firebase
├── .firebaserc
├── firebase.json
├── webapp // My web app. Compiles and runs well.
│ ├── package.json
│ ├── tsconfig.json
│ └── src
└── functions // Only what was autogenerated by firebase-tools.
├── .eslintrc.js
├── package.json
├── tsconfig.json
├── tsconfig.dev.json
└── src
└── index.ts
我做過什么
在我的firebase根檔案夾中,我運行firebase init functions并選擇了正確的專案,使用 TypeScript,使用默認的 ESLint 定義,并安裝包。
我在functions/src/index.ts.
我使用的是最新的 node 16 LTS 和 firebase-tools 版本 10.0.1。
我得到的錯誤
當我npm run build在我的functions檔案夾中運行時,出現這些錯誤。
> build
> tsc
node_modules/@grpc/grpc-js/build/src/object-stream.d.ts:11:18 - error TS2430: Interface 'IntermediateObjectWritable<T>' incorrectly extends interface 'Writable'.
The types returned by 'end(...)' are incompatible between these types.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
11 export interface IntermediateObjectWritable<T> extends Writable {
~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@grpc/grpc-js/build/src/server-call.d.ts:64:5 - error TS2416: Property 'end' in type 'ServerWritableStreamImpl<RequestType, ResponseType>' is not assignable to the same property in base type 'Writable'.
Type '(metadata?: any) => void' is not assignable to type '{ (cb?: (() => void) | undefined): this; (chunk: any, cb?: (() => void) | undefined): this; (chunk: any, encoding: BufferEncoding, cb?: (() => void) | undefined): this; }'.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
64 end(metadata?: any): void;
~~~
node_modules/@grpc/grpc-js/build/src/server-call.d.ts:77:5 - error TS2416: Property 'end' in type 'ServerDuplexStreamImpl<RequestType, ResponseType>' is not assignable to the same property in base type 'Duplex'.
Type '(metadata?: any) => void' is not assignable to type '{ (cb?: (() => void) | undefined): this; (chunk: any, cb?: (() => void) | undefined): this; (chunk: any, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" | undefined, cb?: (() => void) | undefined): this; }'.
Type 'void' is not assignable to type 'this'.
'this' could be instantiated with an arbitrary type which could be unrelated to 'void'.
77 end(metadata?: any): void;
~~~
Found 3 errors.
我試過的
- 嘗試使用最新的 node 14 LTS 恢復到 firebase-tools 版本 9.23.3。同樣的錯誤。
- 從頭開始嘗試一個新的 Firebase 專案。得到了同樣的錯誤。
- 嘗試從我的 M1 Mac 回傳到我以前的 Intel Mac。也沒有幫助。
唯一對我有用的是使用 JS firebase-functions 模板而不是 TS 模板,這似乎是我現在將要進行的。因為它立即生效,而且我部署它時沒有遇到任何問題,而且運行良好。但我真的更喜歡使用 TS。
我絕對有一種感覺,我在這里錯過了一些非常基本的東西。任何幫助將非常感激。謝謝 :)
uj5u.com熱心網友回復:
這是一個已知的兼容性問題@types/node,@grpc/grpc-js如問題 #2002 中所討論的。
當前的解決方案是將您的@types/node依賴項降級回一個版本。
直到它被修補:
- 如果您有 v14.18.4,請回傳 v14.18.3。
- 如果您有 v17.0.6,請回傳 v17.0.5。
- 等等...
您將其添加到您的package.json檔案中:
"@types/node": "14.18.3"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/403094.html
標籤:
