【发布时间】:2021-12-22 02:11:48
【问题描述】:
问题
在我的 TypeScript 项目在 VSCode 中初始化之后,在 official documentation 之后使用 firebase 工具组合 Firebase Cloud Functions,index.ts 文件的第一行显示错误:
Parsing error: Cannot read file '\tsconfig.json' eslint [1,1]
.eslintrc.js 显示错误:
File is a CommonJS module; it may be converted to an ES6 module.ts(80001)
由于所有文件都是自动生成的,因此这些错误完全令人惊讶,我想摆脱它们。
版本
为了记录,这里是安装的版本:
npm --version 8.1.3
tsc --version 4.4.4
node --version 17.0.1
firebase --version 9.22.0
安装过程
这些是我在 VSCode 的 powershell 中使用的命令,带有一些信息/警告:
>npm install -g firebase-tools
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
...
>firebase init
...
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: undefined,
npm WARN EBADENGINE required: { node: '14' },
npm WARN EBADENGINE current: { node: 'v17.0.1', npm: '8.1.3' }
npm WARN EBADENGINE }
...
>npm install firebase-functions@latest firebase-admin@latest --save
...
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
...
>firebase deploy
...
C:\Users\SAMS\firebase_dogout\functions\src\index.ts
1:13 warning 'functions' is defined but never used @typescript-eslint/no-unused-vars
...
Error: functions predeploy error: Command terminated with non-zero exit code2
文件
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
.eslintrc.js
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
"quotes": ["error", "double"],
"import/no-unresolved": 0,
},
};
index.ts
import * as functions from "firebase-functions";
export const helloWorld = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", {structuredData: true});
response.send("Hello from Firebase!");
});
我尝试了什么
- 重新初始化
- 使用
settings.json文件创建.vscode文件夹
{
"eslint.workingDirectories": [
"src" // and "functions"
]
}
- 使用以下行更新 eslintrc.json 文件:
"project":"PROJECT_NAME/tsconfig.json" - 通过在
parserOptions中设置tsconfigRootDir: __dirname来更新.eslintrc.js - 删除 ESLint 扩展。错误消失了,但
firebase deploy命令不允许代码部署。
所以,related thread 并没有真正的帮助
【问题讨论】:
-
您将文件托管在哪里?你能把这个文件放在Cloud storage 中并从那里读取它而不是让它发挥作用吗?
-
index.ts文件在本地托管在../functions/src中。也许我可以将此文件加载到 Cloud Storage 中,但我想将其加载到 Firebase Cloud Functions 以实现 Cloud Functions 功能(我不确定我是否理解您的建议)。
标签: typescript firebase google-cloud-functions eslint