【发布时间】:2021-10-31 21:05:43
【问题描述】:
今天我在做一个 React Web 项目。所以它工作得很好。然后我创建了另一个反应项目。但是其中没有任何 package.lock 文件。所以我使用 npm install 手动创建它。但在那之后,当我使用npm i react-particles-js 命令向该项目添加依赖项时,我收到了这样的错误消息。
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: smart-parking-system@0.1.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR! react@"^17.0.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.0.0" from react-particles-js@3.5.3
npm ERR! node_modules/react-particles-js
npm ERR! react-particles-js@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\User.LAPTOP-3EBUUP6S\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\User.LAPTOP-3EBUUP6S\AppData\Local\npm-cache\_logs\2021-09-02T11_17_21_426Z-debug.log
当我手动创建 package.lock 文件时,我会收到此日志消息。
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
changed 87 packages, and audited 1703 packages in 40s
所以问题是为什么我没有自动获取 package.lock 文件以及为什么我无法正确安装依赖项?
【问题讨论】:
-
你试过用
npm i package name ----legacy-peer-deps安装吗 -
是的。现在它工作正常。但是为什么会这样。在那之前,我的反应很好。但是现在的问题是为什么它没有自动创建 package.lock 文件。它以前工作得很好。发生这种情况是因为新的 create-react-app 版本现在只使用 yarn 吗?
标签: node.js reactjs npm create-react-app npm-install