npm - Package-lock.json 文件未在分支中正确安装 npm
问题描述
[更新]:似乎可以通过package-lock.json
从工作分支复制并将其粘贴到非工作分支来临时解决该问题。
这对我来说没有意义,因为不package-lock.json
应该影响npm install
.
尝试 npm install 时遇到一个奇怪的问题。首先,我从我的主分支开始并运行一个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
在非工作分支中则不会发现漏洞。
解决方案
我也遇到过这个确切的错误,并且花了一段时间才弄清楚出了什么问题 - 提供的错误说明不起作用,运行npm outdated
并将所有依赖项更新到最新版本都不起作用。即使将 package.json 文件的内容换成一个全新的 vianpx creat-react-app
也不适合我。
解决方案:我检查了我的项目所在的父文件夹,发现它也有一个node_modules
文件夹。删除此文件夹为我清除了错误。这有点奇怪,因为删除的文件夹在我的项目文件夹之外,但看起来 NPM 正在目录树中向上工作,寻找任何node_modules
文件夹。
推荐阅读
- openssl - 使用 .pem 文件和 .key 文件生成 .pfx 文件时,没有证书与私钥匹配
- angular - 如何将检查项目从primeng多选推送到本地数组
- django-templates - django-template-pagination 页码超出区域
- javascript - 如何在分支数量上划分预算,并且每个分支在 JavaScript 中以不同的方式划分?
- assembly - ARM 汇编中的偏移量是什么?它是如何工作的?
- html-table - 以编程方式关注元素会导致 VoiceOver 导航中断
我有一张表,我正试图通过 VoiceOver 使其可访问和导航。就其本身而言,该表似乎可以通过 VO 导航,并且似乎符合我发现的大多数可访问性指南。
表格是:
kubernetes - tls-origination: 导入 tls 时路径 istio 无效- spring - Spring Boot 不提供静态资源
- python - 如何指定打开哪一个
- javascript - 如何从提及 discord.js 添加角色