5

When cloning my repo and doing npm install on WSL2, I am getting this ESLint error on my IDE for all .ts files in my project:

ESLint: Parsing error: Cannot read file \\wsl$\ubuntu-20.04\home\project_directory\tsconfig.json

This is showing up because of my parserOptions in my .eslintrc.json file.

My attempts at solving this issue:

  • I followed this thread: Parsing error: Cannot read file '.../tsconfig.json'.eslint, by converting my json to a js file and using __dirname. However that does not fix the issue for me.
  • I also tried going into my IDE and manually selecting eslint from my project's node_modules. Nothing seems to be removing this error for me.
  • The weird thing is if I clone my repo on Windows (not WSL), and open the project on Windows, the project works fine and eslint shows no issues. Not sure why it's not working the same on WSL.

Any help would be appreciated as I am unsure what to do next.

.eslintrc.json

{
    "env": {
        "browser": true,
        "es2021": true,
        "node": true,
        "jest": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking",
        "prettier"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 2021,
        "sourceType": "module",
        "project": "./tsconfig.json"
    },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "@typescript-eslint/restrict-template-expressions": ["error", {
            "allowNumber": true,
            "allowBoolean": true,
            "allowAny": true,
            "allowNullable": true
        }],
        "no-use-before-define": [2, { "functions": false }],
        "no-underscore-dangle": 0,
        "block-scoped-var": 2,
        "no-undef": 2,
        "no-loop-func": 1,
        "no-console": 1,
        "no-debugger": 2,
        "eqeqeq": 2,
        "strict": [2, "function"],
        "no-unused-vars": [2, { "args": "none" }],
        "no-prototype-builtins": "warn"
    }
}

tsconfig.json

{
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */
    /* Basic Options */
    "target": "ES6",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */
    "module": "ESNext",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "sourceMap": true,                           /* Generates corresponding '.map' file. */
    "outDir": "dist",                              /* Redirect output structure to the directory. */
    "strict": true,                                 /* Enable all strict type-checking options. */
    "moduleResolution": "node",                  /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    "esModuleInterop": true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */
  }
}

package.json

{
  "name": "backendbill",
  "version": "21.7.0",
  "description": "Running on AWS EC2 instance for api and bouncer",
  "main": "dist/index.js",
  "type": "module",
  "scripts": {
    "build": "rimraf dist && tsc",
    "test": "npx jest --watch",
    "dev": "cross-env NODE_ENV=development concurrently \"tsc --watch\" \"nodemon -q dist/index.js\"",
    "prod": "cross-env NODE_ENV=production concurrently \"tsc --watch\" \"nodemon -q dist/index.js\"",
    "deploy": "pm2 deploy ecosystem.config.cjs production",
    "lint": "eslint . --ext .ts",
    "stage": "echo \"No tests just yet\"",
    "prepare": "husky install",
    "preserve": "npm run build",
    "format": "prettier --write \"_/_.+(js|json)\""
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/..."
  },
  "author": "Brother Bill",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/..."
  },
  "homepage": "https://github.com/...",
  "dependencies": {
    "@types/body-parser": "^1.19.1",
    "@types/express": "^4.17.13",
    "@types/node": "^16.3.3",
    "body-parser": "^1.19.0",
    "cross-env": "^7.0.3",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "helmet": "^4.6.0",
    "rimraf": "^3.0.2",
    "typescript": "^4.3.5"
  },
  "devDependencies": {
    "@types/jest": "^26.0.24",
    "@typescript-eslint/eslint-plugin": "^4.28.3",
    "@typescript-eslint/parser": "^4.28.3",
    "concurrently": "^6.2.0",
    "eslint": "^7.31.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-promise": "^5.1.0",
    "husky": "^7.0.0",
    "lint-staged": "^11.0.1",
    "nodemon": "^2.0.12",
    "pm2": "^5.1.0",
    "prettier": "^2.3.2",
    "ts-jest": "^27.0.3"
  },
  "lint-staged": {
    "*.{js,ts,cjs}": [
      "eslint --cache --fix",
      "prettier --check"
    ]
  }
}

Config Screenshots:

Automatic:
Automatic

Manual:
Manual

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Brother Bill
  • 117
  • 1
  • 8
  • 1
    is the path to `tsconfig.json` shown in the error message correct? please share screenshots of **Settings | Languages & Frameworks | JavaScript | Code Quality Tools | ESLint** and **Settings | Languages & Frameworks | Node.js and NPM** pages. Also, what do you mean saying that the issue goes away if you close your repo? – lena Sep 13 '21 at 12:16
  • @lena Yes, 'project_directory' is under a different name but all else is fine. I shared screen shots above. One is set to automatic and the other to manual. – Brother Bill Sep 14 '21 at 02:57
  • I apologize, 'close' was a typo and it's been corrected. What I meant was if I clone my repo on Windows and open the project directory in Windows, eslint shows no parsing errors. – Brother Bill Sep 14 '21 at 03:21
  • 3
    Could you also share a screenshot of **Settings | Languages & Frameworks | Node.js and NPM** page? – lena Sep 14 '21 at 12:26
  • 5
    @lena Thank you so much for mentioning that! I realized my Node interpreter was pointed at my Windows installation instead of WSL's. Changing it there fixes the issue for me. – Brother Bill Sep 14 '21 at 16:15
  • Had the same issue. I worked under wsl2 on Windows10. Found out my node was pointing at disk C. When switched to ubuntu nodem this n=mistake wasa gone. – bullet03 Jul 12 '23 at 12:16

0 Answers0