![](/img/trans.png)
[英]Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js
[英]typescript-eslint config: .eslintrc file 'module' is not defined
我正在按照typescript-eslint入門文檔中的描述設置一個新項目。 但是,在我的.eslintrc.js
文件中出現錯誤:
“模塊”未定義。eslint(no-undef)
現在,如果我從配置的extends
中刪除eslint:recommended
,這個錯誤就會消失。 然而,像debugger
或const iAmUnused = true
這樣的典型規則不會被 ESLint 接受,所以 if 感覺有點像打地鼠。
為什么我的 ESLint 文件位於我的項目的根目錄並啟用了eslint:recommended
? 我不想在我的.eslintignore
中包含這個文件,因為在運行我的eslint
命令時,它說這個文件已經被自動忽略,但它不是 ♂️
ESLINTRC:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: '*/tsconfig.json',
},
settings: {
react: {
version: 'detect',
},
},
plugins: ['@typescript-eslint', 'jest', 'react', 'react-hooks'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
'plugin:prettier/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
'prettier/@typescript-eslint',
],
rules: {
'no-unused-vars': 2,
},
env: {
browser: true,
es6: true,
jest: true,
},
overrides: [
{
files: ['**/*.tsx'],
rules: {
'react/prop-types': 'off',
},
},
],
};
TS配置:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"declaration": true,
"declarationDir": "build",
"jsx": "react",
"lib": ["es6", "dom", "es2016", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"rootDir": "./src",
"rootDirs": ["./src"],
"sourceMap": true,
"strict": true,
"target": "es5"
},
"include": ["./src"],
"exclude": ["node_modules", "build", "dist", "src/**/*.stories.tsx", "src/**/*.test.tsx"]
}
env
需要從以下位置更新環境:
env: {
browser: true,
es6: true,
jest: true,
},
包含node: true
用於要解決的module
錯誤。
https://eslint.org/docs/user-guide/configuring#specifying-environments
您需要指定與您的項目相關的環境。
在這種情況下,您可能想要添加commonjs
環境。
不過,我只想考慮關閉no-undef
規則,因為它是 TypeScript 本身已經涵蓋的檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.