简体   繁体   English

通过 ESLint 版本在 vscode 上启动 React 应用程序失败

[英]Start React app fail on vscode by ESLint version

I have an issue that I cannot solve.我有一个我无法解决的问题。 I'm using ESLint in VSCode for my all projects.我在 VSCode 中为我的所有项目使用 ESLint。 Now I created a new react app but when I run it (npm start or yarn start), it throws an error.现在我创建了一个新的 React 应用程序,但是当我运行它(npm start 或 yarn start)时,它会抛出一个错误。

React app use ESLint 5.12.5, is lower version of mine. React 应用程序使用 ESLint 5.12.5,是我的较低版本。 I tried following the steps in the suggestion but ... it's not fixed.我尝试按照建议中的步骤进行操作,但是......它没有修复。

Can anyone solve my issue?谁能解决我的问题?

I tried npm uninstall -g eslint , npm uninstall eslint , npm i ...bla..bla, removed my ESLint extension in my VSCode, and re-created react app.我尝试了npm uninstall -g eslintnpm uninstall eslintnpm i ...bla..bla ,在我的 VSCode 中删除了我的 ESLint 扩展,并重新创建了反应应用程序。 But the error has not been fixed.但错误尚未修复。
I checked eslint -v, it said 5.14.1, but in the error notice, vscode said version 5.16.0 is in node-modules @@.我检查了 eslint -v,它说 5.14.1,但在错误通知中,vscode 说 5.16.0 版本在 node-modules @@ 中。

This is full error notice when I try yarn start or npm start :当我尝试yarn startnpm start时,这是完整的错误通知:

> homework02@0.1.0 start E:\Extenal Code\Hoc JS\ReactJS-iViettech\homework02
> react-scripts 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": "5.12.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:

E:\Extenal Code\Hoc JS\node_modules\eslint (version: 5.16.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 E:\Extenal Code\Hoc JS\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.

I just solved this issue, the error says: The react-scripts package provided by Create React App requires a dependency: "eslint": "5.12.0" (in my case "^5.16.0")我刚刚解决了这个问题,错误说: The react-scripts package provided by Create React App requires a dependency: "eslint": "5.12.0" (在我的例子中是“^5.16.0”)

but also says you have another version at package.json that's E:\\Extenal Code\\Hoc JS\\node_modules\\eslint (version: 5.16.0) in my case was 6.1.0但也说你在 package.json 有另一个版本,即E:\\Extenal Code\\Hoc JS\\node_modules\\eslint (version: 5.16.0)在我的情况下是 6.1.0

so my solution was: I searched for the dependency called eslint and updated the version similar to Create React App expected "eslint": "^5.12.0" (in my case "eslint": "^5.16.0") at package.json Then run npm install and now you can run npm start... if you have troubles with slint-plugin-import just update the version as well, additional you can try installing locally instead of global with --save .所以我的解决方案是:我搜索了名为 eslint 的依赖项,并在 package.json 中更新了类似于 Create React App expected "eslint": "^5.12.0" (在我的情况下为 "eslint": "^5.16.0") 的版本。 json 然后运行npm install ,现在您可以运行 npm start... 如果您在使用slint-plugin-import遇到问题,只需更新版本,另外您可以尝试使用--save本地安装而不是全局安装。

I believe this is an ongoing issue with create-react-app and eslint as detailed at:我相信这是create-react-app和 eslint 的一个持续问题,详见:

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

There are a number of suggestions there, though I'm hoping they will put a more permanent fix in place.那里有很多建议,但我希望他们能提供更永久的修复。

In my case it works like below:在我的情况下,它的工作原理如下:

  1. Create New Project or clone form vcs.创建新项目或克隆表单 vcs。
  2. Create .eslintrc.json file by yourself.自己创建 .eslintrc.json 文件。 Do not use Ctrl+Shift+P ->Eslint:create eslint configuration.不要使用 Ctrl+Shift+P ->Eslint:创建 eslint 配置。

Just try clearing cache and everything will come into normal usage you can use npx create-react-app project-folder-name , this worked for me.只需尝试清除缓存,一切都会正常使用,您可以使用npx create-react-app project-folder-name ,这对我有用。 Use this cmd in your terminal在终端中使用此 cmd

cmd -> npm cache clean —force cmd -> npm cache clean —force

there is different process to make it work just have to follow two installations for the future projects too if you like you can use this too and can work for your projects, cmd line is mentioned below :有不同的过程可以使其工作,只需为未来的项目执行两个安装,如果您愿意,您也可以使用它并且可以为您的项目工作,下面提到了 cmd 行:

cmd 1-> create-react-app my-app --scripts-version @nomoreanalog/react-scripts-eslintless cmd 1-> create-react-app my-app --scripts-version @nomoreanalog/react-scripts-eslintless

cmd 2-> npm install --save-dev babel-plugin-styled-components cmd 2-> npm install --save-dev babel-plugin-styled-components

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

相关问题 如果我在 react-app 中使用 typescript 元组,我会在 vscode 的第 1 行收到 eslint 错误? - If I use a typescript tuple in my react-app i get a eslint error on line 1 in vscode? create-react-app 版本 5 的“eslint-config-react-app”问题 - "eslint-config-react-app" issue with create-react-app version 5 反应启动脚本失败 - fail at react start script 由于缺少模块“eslint/lib/formatters/stylish”,我无法在部署到 GCP 后启动 React 应用程序 - I cant start React app after deploy to GCP because of missing module 'eslint/lib/formatters/stylish' NPX create-react-app 找不到 @typescript-eslint/experimental-utils@2.19.1 的匹配版本 - NPX create-react-app cannot find a matching version for @typescript-eslint/experimental-utils@2.19.1 vscode 和 eslint 上的错误缩进<text> | JSX | 反应本机</text> - vscode and eslint wrong indentation on <Text> | JSX | React Native VSCode ESlint 和 React Typescript 声明类型报错 - VSCode ESlint and React Typescript declaring type gives an error 对于 React 应用程序,vscode 调试器中的断点通常会失败 - Breakpoints in vscode debugger often fail for a React application ESLint 错误 - ESLint 找不到配置“react-app” - ESLint error - ESLint couldn't find the config "react-app" Atom &amp; eslint:找不到模块 'eslint-config-react-app' - Atom & eslint: Cannot find module 'eslint-config-react-app'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM