繁体   English   中英

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

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

我有一个我无法解决的问题。 我在 VSCode 中为我的所有项目使用 ESLint。 现在我创建了一个新的 React 应用程序,但是当我运行它(npm start 或 yarn start)时,它会抛出一个错误。

React 应用程序使用 ESLint 5.12.5,是我的较低版本。 我尝试按照建议中的步骤进行操作,但是......它没有修复。

谁能解决我的问题?

我尝试了npm uninstall -g eslintnpm uninstall eslintnpm i ...bla..bla ,在我的 VSCode 中删除了我的 ESLint 扩展,并重新创建了反应应用程序。 但错误尚未修复。
我检查了 eslint -v,它说 5.14.1,但在错误通知中,vscode 说 5.16.0 版本在 node-modules @@ 中。

当我尝试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.

我刚刚解决了这个问题,错误说: The react-scripts package provided by Create React App requires a dependency: "eslint": "5.12.0" (在我的例子中是“^5.16.0”)

但也说你在 package.json 有另一个版本,即E:\\Extenal Code\\Hoc JS\\node_modules\\eslint (version: 5.16.0)在我的情况下是 6.1.0

所以我的解决方案是:我搜索了名为 eslint 的依赖项,并在 package.json 中更新了类似于 Create React App expected "eslint": "^5.12.0" (在我的情况下为 "eslint": "^5.16.0") 的版本。 json 然后运行npm install ,现在您可以运行 npm start... 如果您在使用slint-plugin-import遇到问题,只需更新版本,另外您可以尝试使用--save本地安装而不是全局安装。

我相信这是create-react-app和 eslint 的一个持续问题,详见:

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

那里有很多建议,但我希望他们能提供更永久的修复。

在我的情况下,它的工作原理如下:

  1. 创建新项目或克隆表单 vcs。
  2. 自己创建 .eslintrc.json 文件。 不要使用 Ctrl+Shift+P ->Eslint:创建 eslint 配置。

只需尝试清除缓存,一切都会正常使用,您可以使用npx create-react-app project-folder-name ,这对我有用。 在终端中使用此 cmd

cmd -> npm cache clean —force

有不同的过程可以使其工作,只需为未来的项目执行两个安装,如果您愿意,您也可以使用它并且可以为您的项目工作,下面提到了 cmd 行:

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

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

暂无
暂无

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

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