Node.js一些报错的解决方案

安装

https://blog.csdn.net/qq_48485223/article/details/122709354

报错1:查询版本

$ npm -v

npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir ‘D:\Node.js\node_cache_logs’
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open ‘D:\Node.js\node_cache_logs\2022-09-12T01_48_51_164Z-debug-0.log’
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir ‘D:\Node.js\node_cache_logs’
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open ‘D:\Node.js\node_cache_logs\2022-09-12T01_48_52_183Z-debug-0.log’
8.15.0

解决方案:
Node.js安装文件夹>>右键-属性>>勾选完全控制,如果无法勾选,对目录下的node_cache与node_global文件夹进行勾选。

Node.js一些报错的解决方案_第1张图片

报错2:全局安装镜像

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path D:\Software\Node.js\node_global\node_modules
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir ‘D:\Software\Node.js\node_global\node_modules’
npm ERR! [Error: EPERM: operation not permitted, mkdir ‘D:\Software\Node.js\node_global\node_modules’] {
npm ERR! errno: -4048,
npm ERR! code: ‘EPERM’,
npm ERR! syscall: ‘mkdir’,
npm ERR! path: ‘D:\Software\Node.js\node_global\node_modules’
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! A complete log of this run can be found in:
npm ERR! D:\Software\Node.js\node_cache_logs\2022-09-12T02_47_24_738Z-debug-0.log

解决方案:
第一步,删除C:\Users目录下.npmrc文件;
第二步,输入命令npm cache clean --force
重新安装cnpm,输入命令cnpm -v显示版本号即安装成功,如下:
Node.js一些报错的解决方案_第2张图片

你可能感兴趣的:(node.js,javascript,npm,经验分享)