简体   繁体   English

在反应 web 应用程序的本地服务器上部署时出现 eslint 错误

[英]eslint error on deployment on local server of react web app

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.这可能不是 Create React App 中的错误,而是您需要在本地修复的错误。

The react-scripts package provided by Create React App requires a dependency: Create React App 提供的 react-scripts package 需要依赖:

"eslint": "5.6.0"

Don't try to install it manually: your package manager does it automatically.不要尝试手动安装:您的 package 管理器会自动安装。 However, a different version of eslint was detected higher up in the tree:但是,在树的较高位置检测到不同版本的 eslint:

D:\chintu\blog-exambunker-master\blog-exambunker-master\node_modules\eslint (version: 5.6.1)

how to install the version 5.6.0 I am installing the eslint it always gets installed with the latest version, can someone suggest me what to do?如何安装版本5.6.0我正在安装 eslint 它总是安装最新版本,有人可以建议我该怎么做吗?

The error is an incompatibility between eslint and babel-eslint versions.该错误是eslintbabel-eslint版本之间的不兼容。 To do solve this, firstly you need to remove your eslint package using npm uninstall eslint .要解决这个问题,首先你需要使用npm uninstall eslint删除你的eslint包。 This command will delete your eslint package.此命令将删除您的eslint包。 After this, you need to install the 5.6.0 version of eslint , so write this command npm i eslint@5.6.0 .之后需要安装5.6.0版本的eslint ,所以写这个命令npm i eslint@5.6.0 I hope that this will be helpful for you.我希望这对你有帮助。 Also, you can delete your node_modules folder and then install it.此外,您可以删除node_modules文件夹,然后安装它。

(Do not do what I did if you don't read everthing I posted) At least with me, I just downgraded my eslint 5.8.0 to 5.6.0 (manually). (如果你没有阅读我发布的所有内容,请不要做我所做的)至少对我来说,我只是将我的 eslint 5.8.0 降级到 5.6.0(手动)。 Why?为什么? Because when I use some eslint library like airbnb, it installs the latest version of eslint (5.8.0) automatically, the problem here is that this version has conflict with the previous eslint version used by react (5.6.0), so when you downgrade, you just return to the previous eslint installed, so it's working fine here, but you've to be careful when you update your react version.因为我在使用airbnb等eslint库的时候,会自动安装最新版本的eslint(5.8.0),这里的问题是这个版本和之前react使用的eslint版本(5.6.0)有冲突,所以当你降级,你只是回到之前安装的 eslint,所以它在这里工作正常,但是当你更新你的 React 版本时你必须小心。

I searched where the eslint was with:我搜索了 eslint 的位置:

npm ls eslint

then I deleted it with:然后我删除了它:

npm uninstall ls eslint

Finally I ran最后我跑了

npm start

and it worked.它奏效了。

I have the exactly same problem.我有完全相同的问题。 I have tried everithing from those Suggestions:我已经从这些建议中尝试了everithing:

  1. Delete package-lock.json (not package.json !) and/or yarn.lock in your project folder.删除项目文件夹中的package-lock.json (不是package.json !)和/或yarn.lock
  2. Delete node_modules in your project folder.删除项目文件夹中的node_modules
  3. Remove eslint from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中的package.json文件中的dependencies和/或devDependencies中删除eslint
  4. Run npm install or yarn , depending on the package manager you use.运行npm installyarn ,具体取决于您使用的包管理器。

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:如果这没有帮助,您还可以尝试其他一些方法:

  1. If you used npm , install yarn and repeat the above steps with it instead.如果您使用npm ,请安装yarn并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 存在已知的包提升问题,这些问题可能会在未来版本中得到解决。

  2. Check if C:\\Users\\User\\node_modules\\eslint is outside your project directory.检查C:\\Users\\User\\node_modules\\eslint是否在您的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了某些东西。

  3. Try running npm ls eslint in your project folder.尝试在您的项目文件夹中运行npm ls eslint This will tell you which other package (apart from the expected react-scripts) installed eslint.这将告诉您安装了 eslint 的其他包(除了预期的 react-scripts)。

nothing worked.没有任何效果。 every time I am doing npm install/yarn it keeps install the old version of eslint.每次我执行npm install/yarn它都会安装旧版本的 eslint。

ok I find my issue: I had npm packeges and some more crap outside the projects folders (on c:/users/user) they may had the old version of eslint.好的,我发现了我的问题:我在项目文件夹之外(在 c:/users/user 上)有 npm packeges 和更多垃圾,他们可能有旧版本的 eslint。 cheack it out and tell me if you still have the problem or not.检查出来,告诉我你是否还有问题。

I deleted a node modules folder that contained an older version of eslint.我删除了一个包含旧版本 eslint 的节点模块文件夹。 I found this to be the easiest solution rather than changing dependencies.我发现这是最简单的解决方案,而不是更改依赖项。

What solved this for me, was that in the error message, it told me that there was eslint installed in project with 5.6.0 and another installed in users/andrew/nodemodules/eslint with a version of 4.1.6 I tried doing a npm uninstall -g eslint but that didnt work so then I just searched for all the files and folders within users/andrew/nodemodules/eslint and deleted them, and it worked for then.为我解决了这个问题的是,在错误消息中,它告诉我在5.6.0项目中安装了 eslint,而在users/andrew/nodemodules/eslint安装了另一个版本为4.1.6我尝试执行npm uninstall -g eslint但这没有用,所以我只是搜索了users/andrew/nodemodules/eslint所有文件和文件夹并删除了它们,然后它就起作用了。 I'm not sure if this is a good way to do it, but its worked.我不确定这是否是一个好方法,但它奏效了。

Create a file .env in your root directory.在您的根目录中创建一个.env文件。

And you can ignore the check by putting您可以通过放置忽略检查

SKIP_PREFLIGHT_CHECK=true

in .env file..env文件中。

Ref: https://github.com/facebook/create-react-app/issues/5247#issuecomment-427221678参考: https : //github.com/facebook/create-react-app/issues/5247#issuecomment-427221678

Edit: This is not the solution to this problem.编辑:这不是解决此问题的方法。 It is just to ignore the error as it is discussed in the issue.只是忽略问题中讨论的错误。

Simple delete package-lock.json and node_modules then run npm install then npm start简单删除 package-lock.json 和 node_modules 然后运行npm install然后npm start

else you could install npm i eslint@5.6.0 then npm start否则你可以安装npm i eslint@5.6.0然后npm start

enjoy your work :)好好工作 :)

  • List item项目清单

Open a NEW terminal window within root.在 root 中打开一个新的终端窗口。

Run the command运行命令

npm ls eslint

this should show you the installations that are 'higher' up the dependency tree.这应该会向您显示依赖树中“更高”的安装。

Navigate into the folder(s) that contain gulp-eslint/eslint/babel-eslint or even a sneaky node_modules/ that shouldn't have been installed globally.导航到包含 gulp-eslint/eslint/babel-eslint 甚至不应该全局安装的偷偷摸摸的 node_modules/ 的文件夹。

Next, run either or all of these commands depending on where the files are situated.接下来,根据文件所在的位置运行其中一个或所有这些命令。

rm -rf node_modules/
rm -rf (name of other folders like eslint/gulp-eslint)

RETURN TO YOUR PROJECT返回您的项目

Better to be safe than sorry, run the following commands to make sure it will work properly again.安全总比抱歉好,运行以下命令以确保它再次正常工作。

Within the root directory of your project在您项目的根目录中

rm -rf node_modules/
rm -rf package-lock.json

(If it didn't remove the node_modules just delete it from your folder) (如果它没有删除 node_modules 只需从您的文件夹中删除它)

Finally, Run the following.最后,运行以下命令。

npm install

then然后

npm start

go to node_modules folder and open react-scripts/package.json , find the eslint dependencies and change it.转到 node_modules 文件夹并打开 react-scripts/package.json ,找到 eslint 依赖项并进行更改。 its fixed this way.它以这种方式固定。

https://github.com/wesbos/eslint-config-wesbos/issues/17 https://github.com/wesbos/eslint-config-wesbos/issues/17

In the above mentioned link they suggested to install @abhijithvijayan/eslint-config as peer dependency.在上面提到的链接中,他们建议安装 @abhijithvijayan/eslint-config 作为对等依赖项。 See if this works for you.看看这是否适合你。

you might install a global eslint like this你可能会像这样安装全局 eslint

{22:14}~/go/src/github.com ➭ npm ls eslint      
/Users/demon
└── eslint@6.1.0 

then run然后运行

{22:14}~/go/src/github.com ➭ npm uninstall eslint

in the global terminal instead of vscode's terminal.在全局终端而不是 vscode 的终端中。 then run然后运行

npm start

I just used this command: "npm uninstall eslint".我刚刚使用了这个命令:“npm uninstall eslint”。 Later I just ran mu=y code using npm run start and it worked.后来我只是使用 npm run start 运行 mu=y 代码,它工作了。 I did not have to delete or edit any file我不必删除或编辑任何文件

将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件。

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.这可能不是 Create React App 中的错误,而是您需要在本地修复的问题。

The react-scripts package provided by Create React App requires a dependency: Create React App 提供的 react-scripts 包需要一个依赖:

"eslint": "5.6.0" "eslint": "5.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:但是,在树的更高位置检测到了不同版本的 eslint:

/Users/macbook/node_modules/eslint (version: 3.19.0) /Users/macbook/node_modules/eslint(版本:3.19.0)

Manually installing incompatible versions is known to cause hard-to-debug issues.众所周知,手动安装不兼容的版本会导致难以调试的问题。

If prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.如果更愿意忽略此​​检查,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 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.删除项目文件夹中的 package-lock.json(不是 package.json!)和/或 yarn.lock。
  2. Delete node_modules in your project folder.删除项目文件夹中的 node_modules。
  3. Remove "eslint" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中的 package.json 文件中的依赖项和/或 devDependencies 中删除“eslint”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的包管理器。

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:如果这没有帮助,您还可以尝试其他一些方法:

  1. If you used npm, install yarn ( http://yarnpkg.com/ ) and repeat the above steps with it instead.如果您使用 npm,请安装 yarn ( http://yarnpkg.com/ ) 并用它重复上述步骤。 This may help because npm has known issues with package hoisting which may get resolved in future versions.这可能会有所帮助,因为 npm 存在已知的包提升问题,这些问题可能会在未来版本中得到解决。

  2. Check if /Users/macbook/node_modules/eslint is outside your project directory.检查 /Users/macbook/node_modules/eslint 是否在您的项目目录之外。 For example, you might have accidentally installed something in your home folder.例如,您可能不小心在主文件夹中安装了某些东西。

  3. Try running npm ls eslint in your project folder.尝试在您的项目文件夹中运行 npm ls eslint。 This will tell you which other package (apart from the expected react-scripts) installed eslint.这将告诉您安装了 eslint 的其他包(除了预期的 react-scripts)。

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.如果没有其他帮助,请将 SKIP_PREFLIGHT_CHECK=true 添加到项目中的 .env 文件中。 That would permanently disable this preflight check in case you want to proceed anyway.如果您无论如何都想继续,这将永久禁用此预检检查。

PS We know this message is long but please read the steps above :-) We hope you find them helpful! PS 我们知道这条消息很长,但请阅读上面的步骤 :-) 我们希望它们对您有所帮助!

npm ERR! npm 错误! code ELIFECYCLE npm ERR!代码 ELIFECYCLE npm ERR! errno 1 npm ERR!错误号 1 npm 错误号! my-app@0.1.0 start: react-scripts start npm ERR! my-app@0.1.0 start: react-scripts start npm ERR! Exit status 1 npm ERR!退出状态 1 npm ERR! npm ERR! npm 错误! Failed at the my-app@0.1.0 start script.在 my-app@0.1.0 启动脚本中失败。 npm ERR! npm 错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional logging output above.上面可能有额外的日志输出。

npm ERR! npm 错误! A complete log of this run can be found in: npm ERR!可以在以下位置找到此运行的完整日志:npm ERR! /Users/macbook/.npm/_logs/2018-11-01T15_26_42_405Z-debug.log /Users/macbook/.npm/_logs/2018-11-01T15_26_42_405Z-debug.log

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

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