1.npm install -g xxx全局安装出错
第一种错误:文件夹权限问题
报错:
Unhandled rejection Error: EPERM: operation not permitted, mkdir 'C:\Program Files (x86)\nodejs\node_cache\_cacache'
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
解决方案:
用$npm config list
命令查看npm的配置
; userconfig C:\Users\xxxxxx\.npmrc
cache = "C:\\Program Files (x86)\\nodejs\\node_cache"
prefix = "C:\\Program Files (x86)\\nodejs\\node_global"
registry = "https://registry.npm.taobao.org/"
此时修改node_cache和node_global的“属性-安全-编辑”,把Users改为完全控制即可
有人可能会发现,npm存在好多地方,
每个npm的模块下都有一个npmrc文件,但是不管如何,在命令行使用npm命令的配置文件都由C:\Users\xxxxxx.npmrc控制,用
$npm config set prefix "D:\nodejs" //配置默认安装路径
$npm config set cache "D:\nodejs" //配置默认缓存路径
修改后的配置也都在C:\Users\xxxxxx.npmrc下。
2.全局安装后,vue、create-react-app等命令无法使用
报错:
'vue' 不是内部或外部命令,也不是可运行的程序或批处理文件。
解决方案:
用$npm config list
命令查看npm的配置
; userconfig C:\Users\xxxxxx\.npmrc
cache = "C:\\Program Files (x86)\\nodejs\\node_cache"
prefix = "C:\\Program Files (x86)\\nodejs\\node_global"
registry = "https://registry.npm.taobao.org/"
打开文件夹,查看vue.cmd是否在文件夹中:
配置环境变量:
系统变量中,添加两个
重新打开命令行,执行命令即可。