Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing error: Cannot read file '\tsconfig.json' eslint after following Firebase Cloud Functions initialization instructions

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] enter image description here

and the .eslintrc.js displays an error:

File is a CommonJS module; it may be converted to an ES6 module.ts(80001) enter image description here

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 [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

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

  1. Reinitialization
  2. Creating the .vscode folder with settings.json file with
 {
   "eslint.workingDirectories": [
       "src" // and "functions"
   ]
 }
  1. Updating your eslintrc.json file with the following line: "project":"PROJECT_NAME/tsconfig.json"
  2. Updating .eslintrc.js by setting tsconfigRootDir: __dirname in parserOptions
  3. 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

like image 585
Michael Zur Avatar asked Aug 31 '25 06:08

Michael Zur


1 Answers

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.

Update

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,
    ...
  },
  // ...
}
like image 178
Michael Zur Avatar answered Sep 02 '25 21:09

Michael Zur