gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:24:50 27 4
gpt4 key购买 nike

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

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

谁能解决我的问题吗?

我尝试了 npm uninstall -g eslintnpm uninstall eslintnpm i ...bla..bla,删除了我的 ESLint 扩展在我的 VSCode 中,并重新创建了 React 应用程序。但错误尚未修复。
我检查了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.

最佳答案

我刚刚解决了这个问题,错误提示:Create React App提供的react-scripts包需要依赖:
“eslint”:“5.12.0”
(在我的例子中为“^5.16.0”)

但也说你在 package.json 有另一个版本E:\Extenal Code\Hoc JS\node_modules\eslint (版本: 5.16.0) 在我的例子中是 6.1.0

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

关于reactjs - 通过 ESLint 版本在 vscode 上启动 React 应用程序失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55788469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com