Problem
Right after my TypeScript project initialization in VSCode using firebase tools for composing Firebase Cloud Functions following the official documentation the very first line of the index.ts
file displays an error:
Parsing error: Cannot read file '\tsconfig.json' eslint [1,1]
and the .eslintrc.js
displays an error:
File is a CommonJS module; it may be converted to an ES6 module.ts(80001)
Since all files are auto-generated these errors are a complete surprise and I want to get rid of them.
Versions
For the record, here are the versions installed:
npm --version 8.1.3
tsc --version 4.4.4
node --version 17.0.1
firebase --version 9.22.0
Installation process
These are the commands I used in the powershell in VSCode with some info/warnings:
>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
Files
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!");
});
What I tried
- Reinitialization
- Creating the
.vscode
folder withsettings.json
file with
{
"eslint.workingDirectories": [
"src" // and "functions"
]
}
- Updating your eslintrc.json file with the following line:
"project":"PROJECT_NAME/tsconfig.json"
- Updating
.eslintrc.js
by settingtsconfigRootDir: __dirname
inparserOptions
- Deleting the ESLint extension. The error was gone, but
firebase deploy
command didn't allow the code deployement.
So, the related thread didn't really help