关于npm install过程失败的几种处理方式

 更新时间:2023年06月28日 09:11:17   作者:赐我一颗平常心  
这篇文章主要介绍了关于npm install过程失败的几种处理方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

npm install过程失败的处理

npm install过程失败

第一种情况

//  首先经过npm install后,会生成node_modules,先清除它
rm -rf node_modules
//  如果项目中有package-lock.json文件
rm package-lock.json
// 然后在继续进行包安装
npm install (或者npm install --save  后者会生成package-lock.json文件)
// 如有提示需执行(npm audit fix)(该处是有些包版本的问题, 需做一个版本替换)
npm audit fix
// 然后可开启程序
node app.js / npm run dev (根据需要进行选择)
// 若运行过程提示缺少包,则继续npm install  包名

第二种情况

// 若是报错关于node@sass类的问题,也需先把之前安装的包删掉
rm -rf node_modules
// 然后执行
npm install --unsafe-perm

npm install 模块失败的原因之没有创建package.json文件

以安装 superagent 为例

npm i superagent

错误日志如下

npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/yallist
npm ERR! dest /Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/.yallist-wfFlDPoD
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/yallist' -> '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/.yallist-wfFlDPoD'
npm ERR!  [Error: EACCES: permission denied, rename '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/yallist' -> '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/.yallist-wfFlDPoD'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rename',
npm ERR!   path: '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/yallist',
npm ERR!   dest: '/Users/zhangchi/node_modules/_minipass@2.9.0@minipass/node_modules/.yallist-wfFlDPoD'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 

以安装 superagent 为例 

```shell
npm i superagent

实际原因就是目录缺少 package.json 文件,执行

npm init --yes

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

最新评论