npm react安装报错的解决办法:1、打开项目中的“package.json”文件,找到dependencies对象;2、将其中的“react.json”移动到“devdependencies”;3、在终端中运行“npm audit --production”即可修复警告。
本教程操作环境:windows10系统、react18.0.0版、dell g3电脑。
npm react 安装报错怎么办?
npm安装react时提示报错
在使用npx create-react-app的安装过程中出现了
6 high severity vulnerabilities
但是后续仍然显示成功安装,按照提示输入npm-audit时候却报错
npm audit fixnpm err! code enolocknpm err! audit this command requires an existing lockfile.npm err! audit try creating one first with: npm i --package-lock-onlynpm err! audit original error: loadvirtual requires existing shrinkwrap file npm err! a complete log of this run can be found in:npm err! c:\users\christine\appdata\local\npm-cache\_logs\2022-10-10t08_34_39_142z-debug-0.log
后续发现是自己把项目的路径输错了,正确输入项目路径时显示提示漏洞的原因
nth-check <2.0.1severity: highinefficient regular expression complexity in nth-check - https://github.com/advisories/ghsa-rp65-9cf3-cjxrfix available via `npm audit fix --force`will install react-scripts@2.1.3, which is a breaking changenode_modules/svgo/node_modules/nth-check css-select <=3.1.0 depends on vulnerable versions of nth-check node_modules/svgo/node_modules/css-select svgo 1.0.0 - 1.3.2 depends on vulnerable versions of css-select node_modules/svgo @svgr/plugin-svgo <=5.5.0 depends on vulnerable versions of svgo node_modules/@svgr/plugin-svgo @svgr/webpack 4.0.0 - 5.5.0 depends on vulnerable versions of @svgr/plugin-svgo node_modules/@svgr/webpack react-scripts >=2.1.4 depends on vulnerable versions of @svgr/webpack node_modules/react-scripts 6 high severity vulnerabilities
一个建议:忽略
npm提示可以使用`npm audit fix --force`进行修复,但是don't be alarmed by vulnerabilities after npm install (voitanos.io)j
建议是忽略这些错误;因为npm只是包管理工具,他不能够解决包自身的缺陷和漏洞,如果强制修复解决的话,很有可能会引起更为严重的错误。
一定要尝试解决的话
打开项目中的package.json文件,找到dependencies对象
"dependencies":{//……}
将其中的react.json移动到devdependencies(没有的话可以自己创建一个),你的版本可能与我的不同,但是这是无关紧要的,只需要移动即可
"devdependencies": { "react-scripts": "5.0.1" },
最后,在终端中运行npm audit --production,即可修复警告
推荐学习:《react视频教程》
以上就是npm react 安装报错怎么办的详细内容。