简体   繁体   English

Create-React-App:在本地机器上部署时出现 ESlint 错误

[英]Create-React-App: ESlint error while deployment on local machine

I am using create-react-app (React v16.12.0).我正在使用 create-react-app (React v16.12.0)。 I am getting following error when I run 'npm start' on mac.在 Mac 上运行'npm start'时出现以下错误。

[1] There might be a problem with the project dependency tree.
[1] It is likely not a bug in Create React App, but something you need to fix locally.
[1]
[1] The react-scripts package provided by Create React App requires a dependency:
[1]
[1]   "eslint": "^6.6.0"
[1]
[1] Don't try to install it manually: your package manager does it automatically.
[1] However, a different version of eslint was detected higher up in the tree:
[1]
[1]   /Users/abz/node_modules/eslint (version: 6.5.1)
[1]
[1] Manually installing incompatible versions is known to cause hard-to-debug issues.
[1]
[1] If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That will permanently disable this message but you might encounter other issues.
[1]
[1] To fix the dependency tree, try following the steps below in the exact order:
[1]
[1]   1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
[1]   2. Delete node_modules in your project folder.
[1]   3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.
[1]   4. Run npm install or yarn, depending on the package manager you use.
[1]
[1] In most cases, this should be enough to fix the problem.
[1] If this has not helped, there are a few other things you can try:
[1]
[1]   5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
[1]      This may help because npm has known issues with package hoisting which may get resolved in future versions.
[1]
[1]   6. Check if /Users/abz/node_modules/eslint is outside your project directory.
[1]      For example, you might have accidentally installed something in your home folder.
[1]
[1]   7. Try running npm ls eslint in your project folder.
[1]      This will tell you which other package (apart from the expected react-scripts) installed eslint.
[1]
[1] If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
[1] That would permanently disable this preflight check in case you want to proceed anyway.
[1]
[1] P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
[1]
[1] react-scripts start exited with code 1

I googled and found我用谷歌搜索发现

  1. following solution suggested by many以下许多人建议的解决方案

    • Delete the eslint and babel-eslint from users/abz/node_modules/ folderusers/abz/node_modules/文件夹中删除eslint and babel-eslint
    • Delete package.json-lock, node_modules from local project从本地项目中删除package.json-lock, node_modules
    • Run npm install and npm start运行npm installnpm start

    I tried it and this solution didn't work for me.我试过了,这个解决方案对我不起作用。

  2. This issue can be mitigated by using这个问题可以通过使用来缓解

    adding an `.env file` in root folder with statement `SKIP_PREFLIGHT_CHECK=true`

    But, it is not the solution for this problem.但是,这不是解决此问题的方法。

Any help?有什么帮助吗?

it happens because there is a dependency installed at a parent level which has different version.发生这种情况是因为在具有不同版本的父级安装了依赖项。 In your case it's /Users/abz/node_modules/eslint .在您的情况下,它是/Users/abz/node_modules/eslint Just run this command from root只需从 root 运行此命令

rm -rf node_modules/eslint

and this should solve your problem.这应该可以解决您的问题。

following Anuj shah & SHAHBAZ replies:遵循 Anuj shah 和 SHAHBAZ 的回复:

  1. rm -rf node_modules/eslint
  2. npm install -g npm@latest

or just do npm i -S fsevents或者只是做npm i -S fsevents

resolved this issue.解决了这个问题。

but i have to do the above steps again and again whenever i install another package.但是每当我安装另一个软件包时,我都必须一次又一次地执行上述步骤。 this is so frustrating...这太令人沮丧了......

does anyone have a better solution for this?有没有人对此有更好的解决方案?

I've done the following steps and solved the problem...我已经完成了以下步骤并解决了问题......

  1. Delete node_modules, package-lock.json / yarn.lock删除 node_modules, package-lock.json / yarn.lock
  2. Add "eslint": "^6.6.0" to your devDependencies将 "eslint": "^6.6.0" 添加到你的 devDependencies
  3. Run npm install / yarn运行 npm install / yarn
  4. Run the eslint --init command运行 eslint --init 命令
  5. Install the eslint plugins you need安装你需要的 eslint 插件

At the root of my C drive, I located and deleted the node_modules folder, since this was pointed out as the folder housing the eslint-lint that conflicted with the one in my project.在我的 C 驱动器的根目录中,我找到并删除了 node_modules 文件夹,因为它被指出是包含与我的项目中的 eslint-lint 冲突的文件夹。 That did the magic!那就是魔法!

You are using multiple different versions of react-script.您正在使用多个不同版本的 react-script。 Update them to use the same version at it should fix your problem更新它们以使用相同的版本应该可以解决您的问题

just run赶紧跑

npm install --save --save-exact react-scripts@4.0.3

or或者

yarn add --exact react-scripts@4.0.3

https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md

this worked for me npm install --save --save-exact react-scripts@latest --force这对我有用 npm install --save --save-exact react-scripts@latest --force

This is a quick less technical hack, to avoid messing with the node_nodules you can just switch root directory of your application这是一个技术含量较低的快速破解,为了避免弄乱 node_nodules,您可以切换应用程序的根目录

So if your application root is like so所以如果你的应用程序根是这样的

 Users/Parent-folder/Current-app

move into into this root instead改为进入这个根目录

 Users/Current-app

and run npm install/yarn and npm run dev/start or yarn dev/start并运行npm install/yarnnpm run dev/startyarn dev/start

this will avoid your application node-modules to conflict with whatever your parent folders modules.这将避免您的应用程序节点模块与您的父文件夹模块发生冲突。

Just run:赶紧跑:

npm uninstall eslint

Error will be gone.错误将消失。

Note: npm uninstall -g eslint did not work in my case注意: npm uninstall -g eslint在我的情况下不起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM