今天查看项目node_modules文件,有2.78G,好家伙,占用空间有点大,然后就删掉了node_modulespackagelock.json文件,重新执行npm install,然后就报错了,之前记得有这样做过,也没有报错呀,离大谱

npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'rename',
npm ERR!     dest: 'D:\XXXXXproject\oss\node_modules\compression-webpack-plugin\package.json'
npm ERR!   },
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   path: 'D:\XXXXX\project\oss\node_modules\compression-webpack-plugin\package.json.3700355834',
npm ERR!   dest: 'D:\XXXXX\project\oss\node_modules\compression-webpack-plugin\package.json',
npm ERR!   parent: 'oss'
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!     C:Program Filesnodejsnode_cache_logs2023-01-12T05_18_52_549Z-debug.log

刚开始以为是自己node.js环境变量配置好,重新检查了一遍,少了这些配置
在这里插入图片描述
在这里插入图片描述
然后重新下载依赖包,发现还是不行,网上解决方案挺多,但总有不适合自己项目

使用npm cache verify清除npm缓存
重新下载依赖包,依旧报错

清除缓存:
Cache verified and compressed (C:Program Filesnodejsnode_cache_cacache):
Content verified: 4661 (496839341 bytes)
Index entries: 7125
Finished in 4.26s

接着再试试别的方法,找到了一个播客是下载的时候后面加上了淘宝镜像

命令npm install --registry=https://registry.npm.taobao.org

注意:每次试之前把失败node_modulespackage-lock.json文件删掉,不然还是会报错

完美解决,虽然不知道前面检查没有影响,但好歹项目可以正常运行node_moudels文件也没有那么大了,恢复到了几百兆

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注