[英]Error: Cannot find module 'eslint/lib/rules/no-unused-expressions'
After installing ESLint through NPM, I'm getting the following error in my browser:通过 NPM 安装 ESLint 后,我在浏览器中收到以下错误:
Error: Cannot find module 'eslint/lib/rules/no-unused-expressions' Referenced from:
错误:找不到模块 'eslint/lib/rules/no-unused-expressions' 引用自:
Any idea what could cause this and how I can fix it?知道什么可能导致这种情况以及我该如何解决吗?
Try these steps:尝试以下步骤:
In case you want to have eslint, try checking if you have in your devDependencies the line below:如果您想要 eslint,请尝试检查您的 devDependencies 中是否有以下行:
"eslint": "5.6.0"
I had this issue while using a create-react-app.我在使用 create-react-app 时遇到了这个问题。 React scripts already come with an eslint version installed and that means you shouldn't need to install eslint on your own.
React 脚本已经安装了 eslint 版本,这意味着您不需要自己安装 eslint。 I fixed this issue by doing the following:
我通过执行以下操作解决了这个问题:
npm install
npm install
npm start
and everything was working fine again npm start
一切正常Deleted node-modules folder删除了 node-modules 文件夹
Deleted my package-lock.json file删除了我的 package-lock.json 文件
Removed eslint from the package.json file从 package.json 文件中删除了 eslint
Installed all packages again再次安装所有软件包
npm install
npm start
and everything was working fine again一切都恢复正常了
Easy fix #1轻松修复 #1
npm i -D --save eslint-loader
Easy fix #2轻松修复 #2
npm i -D --save eslint@5.16.0
Explanation :说明:
eslint-loader/index.js
(so not eslint
).eslint-loader/index.js
触发的(所以不是eslint
)。eslint-loader
and check the version in its package.json
.eslint-loader
并在它的package.json
检查版本。 It's probably quite outdated.eslint-loader
is 4.0.2eslint-loader
的当前版本是 4.0.2eslint/lib/formatters/stylish
to eslint/lib/formatters/<some-other-folder>/stylish
in a newer version of eslint (I think v6).eslint/lib/formatters/stylish
到eslint/lib/formatters/<some-other-folder>/stylish
在eslint的新版本(我认为v6)。 And now this older eslint-loader version is failing to find the updated path in eslint. So either upgrading eslint-loader
to a newer version that knows this new path (Easy fix 1), or downgrading eslint
down to when it had that old path (Easy fix 2), should both work.因此,要么将
eslint-loader
升级到知道这个新路径的新版本(Easy fix 1),要么将eslint
降级到它有旧路径时(Easy fix 2),两者都应该有效。
For the record I think this outdated dependency is coming from webpack, which makes it difficult to debug for the create-react-app folks.作为记录,我认为这个过时的依赖来自 webpack,这使得 create-react-app 人员很难调试。
Make sure you clean your node_modules
.确保清理
node_modules
。 Delete your package-lock.json.删除您的 package-lock.json。 and run the
并运行
npm cache clean --force
to clean the cache. npm cache clean --force
清理缓存。 Now install the eslint
by running below in the directory:现在通过在目录中运行以下来安装
eslint
:
npm i --save eslint
I know it's late to answer, maybe it's gonna help someone who comes to this thread.我知道现在回答已经晚了,也许它会帮助来到这个线程的人。
for linux user and using npx just type npx eslint --init as the documentation says对于 linux 用户并使用npx只需键入npx eslint --init如文档所述
你应该更新 node.js 和 npm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.