1、执行以下指令安装yarn:
npm install -g yarn
出现如下错误:
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path D:\nodejs18\node_cache\_cacache
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'D:\nodejs18\node_cache\_cacache'
npm ERR! [Error: EPERM: operation not permitted, mkdir 'D:\nodejs18\node_cache\_cacache'] {
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'mkdir',
npm ERR! path: 'D:\\nodejs18\\node_cache\\_cacache',
npm ERR! requiredBy: '.'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! Log files were not written due to an error writing to the directory: D:\nodejs18\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
错误原因:
就是权限的问题。因为我们习惯在idea或者webstrom中打开命令行,执行指令。这样在操作有权限的文件就会出错。
解决方案:
打开命令行执行
npm install -g yarn
2、出现npm ERR! code CERT_HAS_EXPIRED问题
原因是证书过期的问题。解决方案:
2.1清除npm缓存
npm cache clean --force
2.2禁用SSL
npm config set strict-ssl false
2.3手动设置npm镜像源
npm config set registry https://registry.npm.taobao.org/