Package-lock.json文件不是npm在分支中正确安装

[更新]:似乎可以通过从工作分支中复制package-lock.json并将其粘贴到非工作分支中来暂时解决此问题。

这对我来说毫无意义,因为package-lock.json不应影响npm install

尝试npm安装时遇到一个奇怪的问题。首先,我从我的master分支开始并运行npm install,我的应用程序可以正常工作。然后,我切换到另一个分支,并从主分支切换到git pull。然后,我尝试运行npm install,然后在尝试运行我的应用程序时出现以下错误:

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:

  "webpack": "4.41.2"

Don't try to install it manually: your package manager does it automatically.
However,a different version of webpack was detected higher up in the tree:

  /Users/t.dammon/work/cpax/cpax-react/node_modules/webpack (version: 4.41.5) 

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 "webpack" 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 /Users/t.dammon/work/cpax/cpax-react/node_modules/webpack is outside your project directory.
     For example,you might have accidentally installed something in your home folder.

  7. Try running npm ls webpack in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed webpack.

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.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

在运行npm install之前,我曾尝试删除节点模块和包锁。我还尝试了错误消息中列出的所有故障排除步骤。

我还比较了非工作分支和工作分支(它们两个都都运行npm install)中的程序包锁定文件,并且似乎非工作分支正在更新一些比工作分支更高的依赖版本分支。

我发现真正有趣的是,如果我在工作分支中运行npm start并拉起我的应用程序,然后切换分支,那么我可以在非工作分支中停止并启动我的应用程序(只要我不要运行npm install)。

所以我的结论是,分支中的npm install正在发生一些时髦的事情,这在其他地方没有发生,但是我真的不知道到底是什么引起了这个问题。

其他细节,当我在工作分支中运行npm install时,我将有一个漏洞需要审核,而在非工作分支中的npm install将不会发现漏洞。

xiong_yingwen 回答:Package-lock.json文件不是npm在分支中正确安装

我也遇到了这个确切的错误,花了一段时间才弄清楚出了什么问题-提供的错误说明不起作用,运行npm outdated并把所有的依赖关系都归到最新不起作用。甚至通过npx creat-react-app换成一个全新的package.json文件的内容对我也不起作用。

解决方案::我检查了项目存储在的 parent 文件夹,发现它也有一个node_modules文件夹。删除此文件夹为我清除了错误。有点奇怪,因为删除的文件夹不在我的项目文件夹之外,但是看起来NPM正在目录树中向上移动,寻找任何node_modules文件夹。

本文链接:https://www.f2er.com/2737800.html

大家都在问