为什么使用react构建项目时显示代码EPERM

问题描述 投票:0回答:1

当我使用

npm i react react-dom
时发生了这种情况

npm error code EPERM
npm error syscall open
npm error path C:\Program Files\nodejs\node_cache\_cacache\tmp\4212eb4d
npm error errno EPERM
npm error FetchError: Invalid response body while trying to fetch https://registry.npmmirror.com/react: EPERM: operation not permitted, open 'C:\Program Files\nodejs\node_cache\_cacache\tmp\4212eb4d'
npm error     at D:\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:170:15
npm error     at async Response.json (D:\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\body.js:75:17)
npm error     at async RegistryFetcher.packument (D:\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:98:25)
npm error     at async RegistryFetcher.manifest (D:\nodejs\node_modules\npm\node_modules\pacote\lib\registry.js:128:23)
npm error     at async #fetchManifest (D:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1199:20)
npm error     at async #nodeFromEdge (D:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1037:19)
npm error     at async #buildDepStep (D:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:901:11)
npm error     at async Arborist.buildIdealTree (D:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:181:7)
npm error     at async Promise.all (index 1)
npm error     at async Arborist.reify (D:\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:131:5) {
npm error   code: 'EPERM',
npm error   errno: 'EPERM',
npm error   syscall: 'open',
npm error   path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache\\tmp\\4212eb4d',
npm error   type: 'system',
npm error   requiredBy: '.'
npm error }
npm error
npm error The operation was rejected by your operating system.
npm error It's possible that the file was already in use (by a text editor or antivirus),
npm error or that you lack permissions to access it.
npm error
npm error If you believe this might be a permissions issue, please double-check the
npm error permissions of the file and its containing directories, or try running
npm error the command again as root/Administrator.
npm error Log files were not written due to an error writing to the directory: C:\Program Files\nodejs\node_cache\_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

我尝试完全打开折叠并使用

npm install -g create-react-app
但仍然错误

reactjs npm
1个回答
1
投票

由于权限问题,您会看到 EPERM 错误。

一般来说,出现这样的错误是因为项目文件夹不在具有完全访问权限的位置。将项目移动到更容易访问的位置,例如

C:\Users\YourUserName\Documents
,然后重试。

如果您不想更改项目的文件夹位置,只需以管理员身份运行终端即可。

© www.soinside.com 2019 - 2024. All rights reserved.