常用npm命令:https://www.runoob.com/nodejs/nodejs-npm.html
npm文档:中文文档
错误1: ERR: Please try running this command again as root/Administrator
说明: 提示要用管理员身份重新安装,网上有说要清除缓存,尝试了行不通。
解决: 直接重新安装(多半是网络原因
)
或者登录用户(尝试了有时候可以)再重新安装
>npm login
Username: test
Password: ******
Email: *******
>npm install --save module
tip:登录之后安装还是报错的话,就多试几次,网络差的情况下也有可能导致安装失败。(错误提示就是让你重新安装)
错误2: ERR! network ‘proxy’ config is set properly
原文错误翻译: 如果有代理就把代理配置正确。
解决:我们这里不使用代理直接设置为null。
>npm config set proxy null
>npm config set https-proxy null
把这两个代理都设置设为null 就可以了。
也可以找到配置文件.npmrc 中进行修改。
错误3: npm publish
ERR! You cannot publish over the previously published versions
err:您不能在以前发布的版本上发布。 每次发布都要修改版本号,要修改version
npm config get registry // 查看
npm config set registry=http://registry.npmjs.org // npm镜像
npm config set registry=https://registry.npm.taobao.org/ // 淘宝镜像
npm config list //查看配置可以看到配置目录: userconfig C:\Users\Administrator\.npmrc
如果当前是淘宝镜像发布是发布不成功的
切换 npm config set registry=http://registry.npmjs.org
再进行发布。 要确定是登录的状态下呦。
错误4: npm 启动项目
ERR! webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
ERR! This is probably not a problem with npm. There is likely additional logging output above.
解决:清除缓存,重新安装依赖。
删除node_modules
和 package-lock.json文件
npm cache 介绍
>npm cache clear --force
>npm install