Reactjs 处理;无法加载插件';反应';在';中声明;。eslintrc';:找不到模块';eslint插件react'&引用;埃斯林特误差
最近,我使用“创建react应用程序”(react 16.9)更新了我的react项目Reactjs 处理;无法加载插件';反应';在';中声明;。eslintrc';:找不到模块';eslint插件react'&引用;埃斯林特误差,reactjs,visual-studio-code,eslint,Reactjs,Visual Studio Code,Eslint,最近,我使用“创建react应用程序”(react 16.9)更新了我的react项目 在更新之前,一切正常,但突然出现以下ESLint错误:(在输出选项卡中) My.eslintrc文件: { "env": { "browser": true, "commonjs": true, "es6": true, "node": t
在更新之前,一切正常,但突然出现以下ESLint错误:(在输出选项卡中)
My.eslintrc文件:
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"react-app",
"eslint:recommended",
"plugin:react/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"settings": {
"react": {
"pragma": "React",
"version": "16.8"
}
},
"plugins": [
"react"
],
"rules": {
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
"semi": "off",
"default-case": [
"error",
{
"commentPattern": "^no default$"
}
],
"no-new-wrappers": 0,
"no-mixed-operators": 0,
"require-atomic-updates": "off",
"comma-dangle": "off",
"no-unused-vars": "off",
"no-useless-constructor": 0,
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/no-unescaped-entities": 0,
"react/display-name": 0,
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/anchor-is-valid": "off",
"no-useless-escape": 0,
"no-console": 0,
"no-debugger": 0,
"no-empty": 0,
"linebreak-style": 0,
"import/first": 0,
"import/imports-first": 0,
"no-shadow": 0,
"disable-next-line": 0,
"no-case-declarations": 0,
}
}
我已经在全球和本地安装了ESLint和ESLint插件react,还有什么我遗漏的吗?找到了。1.仅保留“扩展”部分中的“eslint:recommended”。删除所有其他文件。
2.删除了“插件”部分。
3.重新启动VSCode。
4.工作起来很有魅力 我更新的.eslintrc文件如下所示:
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"commonjs": true,
"node": true,
"es6": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"settings": {
"react": {
"pragma": "React",
"version": "16.9"
}
},
"rules": {
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
"semi": 0,
"default-case": [
"error",
{
"commentPattern": "^no default$"
}
],
"react/jsx-uses-vars": 0,
"react/react-in-jsx-scope": 0,
"no-new-wrappers": 0,
"no-mixed-operators": 0,
"require-atomic-updates": "off",
"comma-dangle": "off",
"no-unused-vars": "off",
"no-useless-constructor": 0,
"react/no-unescaped-entities": 0,
"react/display-name": 0,
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/anchor-is-valid": "off",
"no-useless-escape": 0,
"no-console": 0,
"no-debugger": 0,
"no-empty": 0,
"linebreak-style": 0,
"import/first": 0,
"import/imports-first": 0,
"no-shadow": 0,
"disable-next-line": 0,
"no-case-declarations": 0,
}
}
尝试检查您的ESLint插件工作目录,因为您的项目有一个新的工作目录,使用CreateReact应用程序更新。有同样的问题,我通过检查ESLint插件设置中的工作目录来修复我的问题。我在VS代码中也有同样的问题。在VS code ESLint设置中添加以下设置:
{
"eslint.workingDirectories": [
"Dir1",
"Dir2"
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
]
}
注意:Dir1和Dir2是两个目录,分别有各自的.eslintrc文件。我也有一个类似的错误(我不能确定原因是否相同,但这就是我发现问题的原因) 因此,请确保Require堆栈的路径(在错误中)没有指向项目目录之外 因此,您有一个项目的根目录(其中有node_modules文件夹等)。在终端
$cd..
(转到保存项目的文件夹)中,执行以下操作:
$ ls -a
如果看到名为.eslintrc.js的文件,请将其删除($rm.eslintr.js
)。然后只需重新加载项目,问题(至少在我的情况下)就会消失
$ ls -a