溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

npm react安裝報錯如何解決

發(fā)布時間:2022-12-27 11:40:24 來源:億速云 閱讀:200 作者:iii 欄目:web開發(fā)

這篇“npm react安裝報錯如何解決”文章的知識點大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“npm react安裝報錯如何解決”文章吧。

npm react安裝報錯的解決辦法:1、打開項目中的“package.json”文件,找到dependencies對象;2、將其中的“react.json”移動到“devDependencies”;3、在終端中運行“npm audit --production”即可修復(fù)警告。

npm安裝react時提示報錯

在使用npx create-react-app的安裝過程中出現(xiàn)了

6 high severity vulnerabilities

但是后續(xù)仍然顯示成功安裝,按照提示輸入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

后續(xù)發(fā)現(xiàn)是自己把項目的路徑輸錯了,正確輸入項目路徑時顯示提示漏洞的原因

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`進行修復(fù),但是Don't be alarmed by vulnerabilities after NPM Install (voitanos.io)j

建議是忽略這些錯誤;因為npm只是包管理工具,他不能夠解決包自身的缺陷和漏洞,如果強制修復(fù)解決的話,很有可能會引起更為嚴重的錯誤。

一定要嘗試解決的話

打開項目中的package.json文件,找到dependencies對象

"dependencies":{
//……}

將其中的react.json移動到devDependencies(沒有的話可以自己創(chuàng)建一個),你的版本可能與我的不同,但是這是無關(guān)緊要的,只需要移動即可

"devDependencies": {
    "react-scripts": "5.0.1"
  },

最后,在終端中運行npm audit --production,即可修復(fù)警告。

以上就是關(guān)于“npm react安裝報錯如何解決”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI