【发布时间】:2021-10-18 01:34:11
【问题描述】:
我是 Firebase 函数的新手。我已经将它安装在我的电脑上,现在我正在尝试运行它,但我不断收到此错误:
=== Deploying to 'app'...
i deploying firestore, functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint /Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .
/Users/username/Documents/appdevelopment/app/functions/index.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-
eslint/parser.
The file does not match your project config: index.js.
The file must be included in at least one of the projects provided
/Users/username/Documents/appdevelopment/app/functions/src/index.ts
1:13 warning 'functions' is defined but never used @typescript-eslint/no-unused-
vars
✖ 2 problems (1 error, 1 warning)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging
output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2021-08-15T21_08_19_284Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
该错误以说必须包含文件开始,然后定义了函数但从未使用过。我没有正确安装东西吗?
这是我用来安装 Firebase 功能的命令:
- npm 安装
- npm install -g firebase-tools
- firebase 登录
- firebase 初始化 firestore
- firebase 初始化函数 我在这个文件夹中完成了这一切:Documents/appdevelopment/app/
这是我的测试函数:
const functions = require("firebase-functions");
const admin = require('firebase-admin');
const db = admin.firestore();
admin.initializeApp();
exports.vote = functions.firestore
.document('Votes/{vote}')
.onCreate((document, context) => {
const row = document.data()['id'];
const vote = document.data()['vote'];
if (vote == 1) {
const field = '1star';
} else if (vote == 2) {
const field = '2star';
} else if (vote == 3) {
const field = '3star';
} else if (vote == 4) {
const field = '4star';
} else {
const field = '5star';
}
const incremento = firebase.firestore.FieldValue.increment(1);
const incrementv = firebase.firestore.FieldValue.increment(1);
db.doc('message/'+row).set({field: incremento, 'votes': incrementv})
});
然后我运行 firebase deploy 并得到上面给出的错误。
----- 编辑----
将 index.js 和 index.ts 文件(我不确定我设置为默认语言)添加到 functions/src/ 后,错误变为:
deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint
/Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .
/Users/username/Documents/appdevelopment/
app/functions/src/index.js
0:0 error Parsing error: "parserOptions.project" has been set
for @typescript-eslint/parser.
The file does not match your project config: src/index.js.
The file must be included in at least one of the projects provided
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely
logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2021-08-
16T08_27_58_329Z-debug.log
Error: functions predeploy error: Command terminated with non-
zero exit code1
【问题讨论】:
-
如果您想知道您是否做错了什么,您应该提供清楚完整的步骤来达到这一点。应该有足够的信息,以便任何人都可以按照相同的步骤重现问题。
-
我添加了一些关于我所采取的步骤的信息。
-
如果您使用的是打字稿,我认为您的 Cloud Functions 代码的 (
index.ts) 主源文件应该放在Documents/appdevelopment/app/functions/src/中,Documents/appdevelopment/app/functions/中没有 index.js。由于您使用的工具,它似乎有冲突。让我知道这是否有效。 -
我放了一个 index.ts 和一个 index.js(因为我不确定我是否将 typescript 或 javascript 设置为默认值。)
-
我相信您已经根据问题中的详细信息设置了打字稿。将您的
index.js代码移动/转换为index.ts并删除 index.js`。
标签: typescript firebase npm google-cloud-functions