[英]Cannot deploy Firebase Cloud Function in flutter
当我尝试部署我的 function 时,出现了很多错误。 这是一个全新的 flutter 安装和 Typescript 的 firebase 初始化。
错误:
node_modules/@types/express-serve-static-core/index.d.ts:99:68 - error TS1110: Type expected.
99 type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
~~~
node_modules/@types/express-serve-static-core/index.d.ts:99:77 - error TS1005: '}' expected.
99 type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
~
node_modules/@types/express-serve-static-core/index.d.ts:99:78 - error TS1128: Declaration or statement expected.
99 type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
~
node_modules/@types/express-serve-static-core/index.d.ts:99:80 - error TS1005: ';' expected.
99 type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
~
node_modules/@types/express-serve-static-core/index.d.ts:101:33 - error TS1005: ';' expected.
~
Found 127 errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
这是我的 index.ts
import * as functions from "firebase-functions";
// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
我现在尝试了很多解决方案,但没有一个有效,我尝试做的导出是演示,所以不应该有任何错误。我在我的 mac 上升级了 flutter 和 firebase cli。
如果您处于基础项目的默认配置中,则 eslint 会强制执行一种非常固执己见的风格。 只需运行npx eslint --ext.js,.ts. --fix
npx eslint --ext.js,.ts. --fix
在您的functions目录中会将此样式应用于您的index.ts ,从而避免在预部署脚本期间出现问题。
如果此后问题仍然存在(在 function 文件夹中运行firebase deploy
时出现同样的错误),重新安装模块也可以解决问题,因为它们似乎会导致问题。 (您可以通过在运行npm i
之前在函数目录中运行rm -r node_modules
来再次安装它们。)
最后,您在问题中似乎对 Firebase 和 Flutter 感到有些困惑,也许向我们解释一下 Flutter 与您的项目有何关系可以帮助我们提供更好的建议。
通过在我的 package.json 中选择这个来解决
"dependencies": {
"firebase-admin": "^8.5.0",
"firebase-functions": "^3.0.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"tslint": "~5.8.0",
"typescript": "4.1.2"
},
"resolutions": {
"@types/express-serve-static-core": "4.17.20",
"@types/express": "4.17.2"
},
然后运行命令: rm -r node_modules
然后在使用命令安装所有内容后: npm i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.