node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - 错误 TS1005: ']' 预期

Posted

技术标签:

【中文标题】node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - 错误 TS1005: \']\' 预期【英文标题】:node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - error TS1005: ']' expectednode_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - 错误 TS1005: ']' 预期 【发布时间】:2019-12-06 03:25:54 【问题描述】:

在我的 Ionic 3 项目中执行命令 firebase deploy --only function 时出现以下错误。 This solution 不适合我。

Running command: npm --prefix "$RESOURCE_DIR" run build
> functions@ build /Users/myuser/Project/functions
> tsc

node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - error TS1005: ']' expected.
4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                             ~

node_modules/firebase-functions/lib/function-configuration.d.ts:4:66 - error TS1134: Variable declaration expected.
4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                   ~~~~~~~~~~

node_modules/firebase-functions/lib/function-configuration.d.ts:4:153 - error TS1005: ';' expected.
4 export declare const SUPPORTED_REGIONS: readonly ["us-central1", "us-east1", "us-east4", "europe-west1", "europe-west2", "asia-east2", "asia-northeast1"];
                                                                                                                                                          ~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:61 - error TS1005: ']' expected.
16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                               ~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:63 - error TS1134: Variable declaration expected.
16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                                 ~~~~~~~

node_modules/firebase-functions/lib/function-configuration.d.ts:16:93 - error TS1005: ';' expected.
16 export declare const VALID_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB"];
                                                                                               ~

当我查看文件 node_modules/firebase-functions/lib/function-configuration.d.ts 时,它显示语法错误。


版本详情:

"angularfire2": "^5.2.1",
"firebase": "^6.3.1",
"firebase-admin": "^8.2.0",
"firebase-functions": "3.2.0",
"typescript": "^3.5.3"

【问题讨论】:

【参考方案1】:

npm install -g typescript@3.5.3 为我工作。我认为更高版本也可以。更新全局打字稿版本很重要,因为我的本地打字稿版本更新不起作用

【讨论】:

npm install -g typescript@3.5.3 后还是一样的错误。正如我提到的我的版本 "typescript": "^3.5.3" 我真正的意思是版本升级,因为我通过升级 3.3.x --> 3.5.x 修复了完全相同的错误。你用过“-g”标志吗?另外升级你的 npm firebase-tools 和 firebase-functions 包 是的,我使用了 -g 标志。我也尝试过安装 firebase-tools。请告诉我如何升级或重新安装 firebase-function 包。【参考方案2】:

从github issue that you linked 和错误信息本身来看,错误似乎是由于新的readonly tuples 功能造成的。它是在typescript@3.4.0 中引入的,所以理论上任何高于此的打字稿版本都应该可以工作。

事实上,firebase-functions@3.2.0 使用 typescript@3.5.2 所以我建议你使用相同或更高的。


话虽如此,我看到您已经使用了typescript@3.5.3,但仍然弹出错误。

版本详情:

"angularfire2": "^5.2.1",
"firebase": "^6.3.1",
"firebase-admin": "^8.2.0",
"firebase-functions": "3.2.0",
"typescript": "^3.5.3"

这可能是因为其他包在内部使用了不同的(较旧的)打字稿版本。请检查您的 package-lock.json(或 yarn.lock)以确认。

如果不是这样,那么我的下一个最佳猜测是内部ionic-app-scripts is using older typescript。

【讨论】:

【参考方案3】:

检查是否在此文件的开头添加了任何空间。我遇到了同样的问题,在删除文件顶部的空格后它正在工作。

【讨论】:

【参考方案4】:

在我的情况下,我刚刚从我的 packege.json 中删除了存根类型,它开始为我工作 只是更新一切都不起作用,因为这个旧东西与新版本的 firebase 不兼容 好吧,您在问题中没有提到您的依赖项中确实存在此问题,但我 100% 确定问题出在此处,因为我因此花了一整夜:

"dependencies": 
   "@types/firebase": "^3.2.1",  <<====== this is shit man
   "@types/fs-extra": "^8.0.1",
   "@types/mongoose": "^5.5.43",
   "@types/request": "^2.48.4",
   "actions-on-google": "^2.12.0",
   "bcrypt-inzi": "^1.0.7",
   "body-parser": "^1.18.3",
   "dialogflow-fulfillment": "^0.6.1",
   "express": "^4.17.1",
   "firebase-admin": "^8.6.0",
   "firebase-functions": "^3.3.0",
   "fs-extra": "^8.1.0",
   "mongoose": "^5.8.9",
   "request": "^2.88.0"
 ,

您在运行 npm i 时是否注意到此警告

npm WARN deprecated @types/firebase@3.2.1: This is a stub types definition for Firebase API (https://www.firebase.com/docs/javascript/firebase). Firebase API provides its own type definitions, so you don't need @types/firebase installed!

因为 firebase 函数有自己的类型文件,所以现在根本不需要

【讨论】:

以上是关于node_modules/firebase-functions/lib/function-configuration.d.ts:4:64 - 错误 TS1005: ']' 预期的主要内容,如果未能解决你的问题,请参考以下文章