【问题标题】:Getting error after upgrading eslint version升级 eslint 版本后报错
【发布时间】:2021-11-16 12:02:19
【问题描述】:

我在我的 react 开源项目中设置了 eslint+prettier+husky。当我在设置后运行 npm start 时,它向我显示此错误消息。

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "eslint": "^6.6.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of eslint was detected higher up in the tree:

  /Users/rishipurwar/coding-space/node_modules/eslint (version: 7.32.0) 

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /Users/rishipurwar/coding-space/node_modules/eslint is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls eslint in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed eslint.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! codingspace@0.1.0 start: `npm run watch:css && react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the codingspace@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

请大家帮帮我。

【问题讨论】:

    标签: reactjs eslint eslintrc


    【解决方案1】:

    如错误中所述,只需尝试其中一种

      1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
      2. Delete node_modules in your project folder.
      3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
      4. Run npm install or yarn, depending on the package manager you use.
    

    【讨论】:

    • 这将删除 eslint 最新版本。那么 eslint 将无法正常工作。我试着这样做
    • 不建议在 create react app 中手动更改 eslint 版本,如果要手动配置,可以运行 npm 弹出。
    • 我想我需要更新 reac-script 但我不确定。 stackoverflow.com/questions/60124662/…
    • 这可能有效,但创建反应应用程序从不支持任何模块 iirc 的最新版本。手动更改包版本的唯一方法是弹出创建反应应用程序。
    猜你喜欢
    • 2023-02-01
    • 2021-01-20
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2021-03-08
    • 2018-12-30
    相关资源
    最近更新 更多