npm install 時,會出現很多錯誤,包括配置錯誤等。
以webpack中安裝autoprefixer爲例:
終端輸入:
npm install autoprefixer
報出一堆錯
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:223:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.3.0
gyp ERR! command "/usr/local/bin/node"
...
不管他們!
在終端逐行輸入下列代碼:
sudo rm -rf ~/.node-gyp
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm i --unsafe-perm
完成後,重啓終端項目,若出現很多漏洞vulnerabilities
found 274 vulnerabilities (1 low, 2 moderate, 271 high)
終端提示你
run “npm audit fix” to fix them
那就輸入
npm audit fix
等待,完成修復。
再輸入最初要安裝插件的命令行:
npm install autoprefixer
安裝成功不報錯。
PS:其實報錯並不影響對應文件的使用,嘗試了關掉終端重新安裝又會出現很多錯,上面的安裝步驟走一遍還挺需要時間的,終端安裝不管你的文件是否已經安裝都會重新安裝一遍,如果不是強迫症這類報錯可以忽略不計。