前端项目更新,执行npm install 安装依赖的时候,经常会出现一些莫名奇妙的问题,其中由于开发在本地编写的时候,可能会引用一些私有包,部署到服务器时就会出现问题,下面是排查过程。
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in: /usr/local/www/.npm/_logs/2024-10-28T10_39_48_122Z-debug-0.log
错误原因: 私有包需要用户权限
排查解决过程:
1、确认.npmrc配置文件中设置的源地址不是私有库地址。
npm config get registry
设置为阿里源:npm config set registry https://registry.npmmirror.com
2、查看日志(此方法解决)
查看/usr/local/www/.npm/_logs/2024-10-28T10_39_48_122Z-debug-0.log 日志文件
确认异常包具体报错原因,如果.npmrc文件中是公有库地址,异常报错为私有库地址,则说明有缓存。
解决:删除node_modules和package-lock.json ,重新执行npm install