当克隆我的存储库并在 WSL2 上执行 npm install 时,我在 IDE 上针对项目中的所有 .ts 文件收到此 ESLint 错误:
ESLint:解析错误:无法读取文件
\\wsl$\ubuntu-20.04\home\project_directory\tsconfig.json
这是因为我的
parserOptions
文件中的 .eslintrc.json
而出现的。
我尝试解决这个问题:
__dirname
。然而
这并不能解决我的问题。eslint
我的项目是node_modules
。似乎没有什么可以消除这个错误
对我来说。eslint
没有显示任何问题。不知道为什么它在 WSL 上的工作效果不一样。任何帮助将不胜感激,因为我不确定下一步该做什么。
.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"
]
}
}
配置截图: