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.
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
These are the commands I used in the powershell in VSCode with some info/warnings:
>npm install -g firebase-tools
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: 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 [email protected]: 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 [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: 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 [email protected]: 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
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}
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,
},
};
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!");
});
.vscode
folder with settings.json
file with {
"eslint.workingDirectories": [
"src" // and "functions"
]
}
"project":"PROJECT_NAME/tsconfig.json"
.eslintrc.js
by setting tsconfigRootDir: __dirname
in parserOptions
firebase deploy
command didn't allow the code deployement.So, the related thread didn't really help
Ok, I have solved the problem with a great help of this github thread False positive Error - TS6133 error (declared but its value is never read) report.
I have changed "noUnusedLocals"
setting in the tsconfig.json
file from the default true
to false
, so the file becomes:
"compilerOptions": {
...
"noUnusedLocals": false,
...
}
However, the strange thing is that after successfully deploying functions to Firebase Cloud Fuctions
using this setting and afterwards reverting the changes, the redeployment doesn´t show any error and is successful as well.
After retrying it a few time I must admit that the solution is different.
Turns out that the related stackoverflow thread did help, in particular @cherryblossom solution. Setting tsconfigRootDir: __dirname
in the .eslintrc.js
file and restarting the VSCode solves the problem.
.eslintrc.js
:
module.exports = {
// ...
parserOptions: {
...
tsconfigRootDir: __dirname,
...
},
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With