• 为什么配置了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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24

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

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

      npm config get cache
      
      • 1

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

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

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

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

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

      npm install three
      
      • 1

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

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

  • 相关阅读:
    【前端】CSS基础选择器
    ​苹果应用高版本出现:“无法安装此app,因为无法验证其完整性”是怎么回事?竟然是错误的?
    Python 爬虫—scrapy
    SpringBoot配置文件的加载顺序
    算法---解码方法(Kotlin)
    [论文评析]AdaptivePose: Human Parts as Adaptive Points,AAAI 2022
    GateWay实现负载均衡
    面试被问到不懂的东西,是直接说不懂还是坚持狡辩一下?
    Excel VS BI,谁才是真正的大数据分析工具?
    Vue中如何进行图表绘制
  • 原文地址:https://blog.csdn.net/weixin_43064364/article/details/133469105