You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在WSL Ubuntu执行npm create vite@latest时遇EPERM权限错误

解决WSL Ubuntu中执行npm create vite@latest时的EPERM权限错误

问题现象

在WSL Ubuntu环境执行:

npm create vite@latest

触发以下权限错误:

Error: EPERM: operation not permitted, mkdir 'C:\Windows\app'
    at Object.mkdirSync (node:fs:1395:3)
    at Zr (file:///C:/Users/Karl/AppData/Local/npm-cache/_npx/1415fee72ff6294b/node_modules/create-vite/dist/index.mjs:48:7741)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errno: -4048,
  syscall: 'mkdir',
  code: 'EPERM',
  path: 'C:\\Windows\\app'
}

错误核心是脚本错误尝试在Windows系统目录C:\Windows下创建文件夹,而WSL进程无该目录写入权限。

解决方案

  • 切换到WSL原生文件系统执行命令
    不要在Windows挂载路径(如/mnt/c)下运行初始化命令,切换到WSL用户主目录:

    cd ~
    npm create vite@latest
    

    Vite会在当前目录创建项目,避免触碰Windows系统目录。

  • 清理npx缓存后重试
    缓存的create-vite脚本可能存在路径识别问题,清理后重新拉取:

    npx clear-npx-cache
    npm create vite@latest
    
  • 修正npm全局安装路径配置
    检查当前npm的全局prefix配置:

    npm config get prefix
    

    如果返回Windows系统路径(如C:\Windows),修改为WSL内的用户目录:

    npm config set prefix ~/.npm-global
    

    然后将该路径添加到环境变量,确保全局命令可正常调用:

    echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    

内容的提问来源于stack exchange,提问作者Lo10Th

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 03:42:37