为什么配置了npm的全局安装路径 执行npm 命令 还是走到其他目录

为什么配置了npm的全局安装路径 执行npm 命令 还是走到其他目录,如何解决

报错信息

执行命令以及报错信息:

PS C:\Study\vue\therejsLearn\02-three_basic> npm install three
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path C:\Program Files\nodejs\node_cache\_cacache\index-v5\0d\6d
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_cacache\index-v5\0d\6d'
npm ERR!  [Error: EPERM: operation not permitted, mkdir 'C:\Program Files\nodejs\node_cache\_cacache\index-v5\0d\6d'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'C:\\Program Files\\nodejs\\node_cache\\_cacache\\index-v5\\0d\\6d',
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: C:\Program Files\nodejs\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

问题可能出在 npm 的缓存目录上,它仍然指向默认的全局 npm 缓存目录,而不是您自定义的全局包安装路径。您可以尝试修改 npm 的缓存目录路径以解决这个问题。请按照以下步骤操作:

  1. 查看 npm 的缓存目录路径: 在命令行中运行以下命令来查看 npm 的缓存目录路径:

    npm config get cache
    

    如果它显示的路径是 C:\Program Files\nodejs\node_cache 或类似的默认路径,请继续下一步。

  2. 修改 npm 的缓存目录路径: 使用以下命令将 npm 的缓存目录路径更改为您的自定义全局包安装路径,例如 C:\SofeFile\nodejs\node_cache

    npm config set cache C:\SofeFile\nodejs\node_cache
    

    这将确保 npm 缓存与全局包安装路径一致。

  3. 重新运行安装命令: 最后,再次运行您的安装命令:

    npm install three
    

    确保使用正确的路径执行此命令。

这样做后,npm 应该将包下载并缓存在新的路径下,而不会出现权限问题。如果问题仍然存在,请提供更多信息,以便我可以继续协助您解决问题。

你可能感兴趣的:(vue,npm,前端,node.js)