[英]typescript-eslint config: .eslintrc file 'module' is not defined
I am setting up a new project as described in the typescript-eslint getting started docs.我正在按照typescript-eslint入门文档中的描述设置一个新项目。 However, in my
.eslintrc.js
file I am getting an error:但是,在我的
.eslintrc.js
文件中出现错误:
'module' is not defined.eslint(no-undef)
“模块”未定义。eslint(no-undef)
Now, if I remove eslint:recommended
from the extends
of the config, this error goes away.现在,如果我从配置的
extends
中删除eslint:recommended
,这个错误就会消失。 However, typical rules like debugger
or const iAmUnused = true
do not get picked up by ESLint, so if feels a little like whack-a-mole.然而,像
debugger
或const iAmUnused = true
这样的典型规则不会被 ESLint 接受,所以 if 感觉有点像打地鼠。
Why is my ESLint file being picked up when it's in the root of my project with the eslint:recommended
enabled?为什么我的 ESLint 文件位于我的项目的根目录并启用了
eslint:recommended
? I don't want to include this file in my .eslintignore
because when running my eslint
command, it says this file is already automatically ignored, but it's not ♂️我不想在我的
.eslintignore
中包含这个文件,因为在运行我的eslint
命令时,它说这个文件已经被自动忽略,但它不是 ♂️
ESLINTRC: 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',
},
},
],
};
TSConfig: 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"]
}
Looks like the env
needed to be updated from: env
需要从以下位置更新环境:
env: {
browser: true,
es6: true,
jest: true,
},
to include node: true
for the module
error to be resolved.包含
node: true
用于要解决的module
错误。
https://eslint.org/docs/user-guide/configuring#specifying-environments https://eslint.org/docs/user-guide/configuring#specifying-environments
You need to specify the environment(s) that are relevant to your project.您需要指定与您的项目相关的环境。
In this case, you would probably want to add the commonjs
environment.在这种情况下,您可能想要添加
commonjs
环境。
I would just consider turning off the no-undef
rule though, as it's a check that's already covered by TypeScript itself.不过,我只想考虑关闭
no-undef
规则,因为它是 TypeScript 本身已经涵盖的检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.