简体   繁体   English

添加 webpack 时反应项目依赖错误

[英]React project dependency error while adding webpack

i have installed webpack with below command我已经使用以下命令安装了 webpack

yarn add webpack --dev

and after i ran yarn start command inside my react app folder在我的 react app 文件夹中运行 yarn start 命令后

D:\Workspace\fuel-man-ui\fuel-man-ui>yarn start

Getting below error.低于错误。

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

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

"webpack": "4.29.6" “网络包”:“4.29.6”

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

D:\Workspace\fuel-man-ui\fuel-man-ui\node_modules\webpack (version: 4.41.0) D:\Workspace\fuel-man-ui\fuel-man-ui\node_modules\webpack(版本:4.41.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.如果您希望忽略此检查,请将 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 "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.从项目文件夹中 package.json 文件中的依赖项和/或 devDependencies 中删除“webpack”。
  4. Run npm install or yarn, depending on the package manager you use.运行 npm install 或 yarn,具体取决于您使用的 package 管理器。

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 已知 package 提升问题,这些问题可能会在未来的版本中得到解决。

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

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

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 我们知道这条信息很长,但请阅读上面的步骤:-) 我们希望它们对您有所帮助!

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.错误命令失败,退出代码为 1。有关此命令的文档,请访问https://yarnpkg.com/en/docs/cli/run

i have deleted node_modules from my project and devdependencies, also i have removed global node_modules and cache. still getting same error.

I ran npm ls webpack and got below tree我跑了npm ls webpack并在树下

fuel-man-ui@0.1.0 D:\Workspace\fuel-man-ui\fuel-man-ui
+-- react-scripts@3.0.1
| `-- webpack@4.29.6
|   `-- webpack@4.41.0  extraneous
`-- webpack@4.41.0

npm ERR! extraneous: webpack@4.41.0 D:\Workspace\fuel-man-ui\fuel-man-ui\node_modules\react-scripts\node_modules\webpack\node_modules\webpack

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

"webpack": "4.29.6" “网络包”:“4.29.6”

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

In project root delete node_modules and yarn.lock.在项目根目录中删除 node_modules 和 yarn.lock。 In package.json remove webpack from the dependencies and run yarn again.在 package.json 从依赖项中删除 webpack 并再次运行纱线。

If you want to modify webpack.config for this project you can run yarn eject from here on you are responsible for the webpack.config so it will be harder to update react scripts.如果你想为此项目修改 webpack.config,你可以从这里运行yarn injection,你负责 webpack.config,因此更新反应脚本会更困难。

If you don't want to be responsible for the webpack.config you could try to use react-app-rewired an article on this is here如果您不想对 webpack.config 负责,您可以尝试使用react-app-rewired这篇文章在这里

You should create .env file in the root (not inside src folder) and add SKIP_PREFLIGHT_CHECK=true Then you can use yarn start or npm start .您应该在根目录(不在src文件夹内)创建.env文件并添加SKIP_PREFLIGHT_CHECK=true然后您可以使用yarn startnpm start It works!有用!

Yesterday I had the same issue.昨天我有同样的问题。 In my case it turned out, that I had two installations of node (one using brew , one using downloaded dmg file).就我而言,事实证明,我安装了两个node (一个使用brew ,一个使用下载的 dmg 文件)。 It helped when I removed the one installed via brew.当我删除通过 brew 安装的那个时,它有所帮助。

The file.env with added SKIP_PREFLIGHT_CHECK=true添加了SKIP_PREFLIGHT_CHECK=true的 file.env

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

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