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

时间:2019-07-28 16:25:34

标签: typescript firebase google-cloud-functions

在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时,它显示了语法错误。

版本详细信息:

"firebase": "^6.3.1",

"firebase-admin": "^8.2.0",

"firebase-functions": "3.2.0",

"angularfire2": "^5.2.1"

"typescript": "^3.5.3"

4 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

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

答案 2 :(得分:1)

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

答案 3 :(得分:0)

就我而言,我刚刚从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函数具有其自己的键入文件,因此现在完全不需要