场景:
使用npm安装的时候,报了以下错误:
npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path D:\install\nodejs\node_cache\_cacache\tmp\cc39afea
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/font-spider: EPERM: operation not permitted, unlink 'D:\install\nodejs\node_cache\_cacache\tmp\cc39afea'
npm ERR! at D:\Node\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm ERR! at async Response.json (D:\Node\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm ERR! at async RegistryFetcher.packument (D:\Node\node_modules\npm\node_modules\pacote\lib\registry.js:94:25)
npm ERR! at async RegistryFetcher.manifest (D:\Node\node_modules\npm\node_modules\pacote\lib\registry.js:118:23)
npm ERR! at async [nodeFromEdge] (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1059:19)
npm ERR! at async [buildDepStep] (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:929:11)
npm ERR! at async Arborist.buildIdealTree (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:207:7)
npm ERR! at async Arborist.reify (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:159:5)
npm ERR! at async Install.exec (D:\Node\node_modules\npm\lib\commands\install.js:146:5)
npm ERR! at async module.exports (D:\Node\node_modules\npm\lib\cli.js:134:5)
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/font-spider: EPERM: operation not permitted, unlink 'D:\install\nodejs\node_cache\_cacache\tmp\cc39afea'
npm ERR! at D:\Node\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm ERR! at async Response.json (D:\Node\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm ERR! at async RegistryFetcher.packument (D:\Node\node_modules\npm\node_modules\pacote\lib\registry.js:94:25)
npm ERR! at async RegistryFetcher.manifest (D:\Node\node_modules\npm\node_modules\pacote\lib\registry.js:118:23)
npm ERR! at async [nodeFromEdge] (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1059:19)
npm ERR! at async [buildDepStep] (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:929:11)
npm ERR! at async Arborist.buildIdealTree (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:207:7)
npm ERR! at async Arborist.reify (D:\Node\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:159:5)
npm ERR! at async Install.exec (D:\Node\node_modules\npm\lib\commands\install.js:146:5)
npm ERR! at async module.exports (D:\Node\node_modules\npm\lib\cli.js:134:5) {
npm ERR! code: 'EPERM',
npm ERR! errno: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'D:\\install\\nodejs\\node_cache\\_cacache\\tmp\\cc39afea',
npm ERR! type: 'system',
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! A complete log of this run can be found in:
npm ERR! D:\install\nodejs\node_cache\_logs\2023-05-10T06_10_24_466Z-debug-0.log
以上报错信息的有效信息我分别用不同的背景区分开。
绿色背景:
绿色背景的是它给出报错的原因。
翻译大概就是:这个操作不被系统允许。可能的原因是文件正被打开或者使用的权限不够。
橙色背景:
橙色的是他尝试给出的解决方案。
1.文件的权限够不够。
这个的解决方案就是去到对应的报错的目录下把对应的文件目录的权限改成当前系统用户可以操作(读写那些全部勾上)。
看网上其他人有执行完这步就解决了的,但是执行完这步我再次安装还是会报同样的错误。于是我继续尝试第二个解决方案。
2.是否是对应的系统用户正在使用。
用管理员模式打开cmd/vscode,再次在终端执行要安装的安装命令。
成功!!
我公司的其他同事都是直接安装就好了,不知道是不是因为我的node.js装在了D盘导致了这些权限问题。。。
红色背景:
其实当我看到D:\install\nodejs\node_cache\_cacache\tmp\cc39afea这个文件路径的时候,我就感觉步骤一对我来说行不通了,cc39afea这个感觉是临时文件,是我运行的时候才生成的,每次都不一样,根本不可能在安装前就修改文件权限