npm react安装报错如何解决

发布时间:2022-12-27 11:40:24 作者:iii
来源:亿速云 阅读:175

这篇“npm react安装报错如何解决”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“npm react安装报错如何解决”文章吧。

npm react安装报错的解决办法:1、打开项目中的“package.json”文件,找到dependencies对象;2、将其中的“react.json”移动到“devDependencies”;3、在终端中运行“npm audit --production”即可修复警告。

npm安装react时提示报错

在使用npx create-react-app的安装过程中出现了

6 high severity vulnerabilities

但是后续仍然显示成功安装,按照提示输入npm-audit时候却报错

 npm audit fix
npm ERR! code ENOLOCK
npm ERR! audit This command requires an existing lockfile.
npm ERR! audit Try creating one first with: npm i --package-lock-only
npm 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.1
Severity: high
Inefficient Regular Expression Complexity in nth-check - https://github.com/advisories/GHSA-rp65-9cf3-cjxr
fix available via `npm audit fix --force`
Will install react-scripts@2.1.3, which is a breaking change
node_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,即可修复警告。

以上就是关于“npm react安装报错如何解决”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

推荐阅读:
  1. 如何能分清npm cnpm npx nvm
  2. react组件从搭建脚手架到在npm发布的步骤实现

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

npm react

上一篇:creat react app报错如何解决

下一篇:react中如何设置focus

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》