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'snode_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: