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

Windows系统下Bigcommerce主题目录npm install报错排查求助

问题:Windows下Bigcommerce主题执行npm install时git克隆node-sass报错

系统信息

  • Node.js版本:20.5.0
  • npm版本:9.8.1
  • Chocolatey版本:2.2.0
  • Git版本:2.41.0.windows.3

错误详情

在目录C:\Website\Stencil for website\Fortune+31072023-2.8.0执行npm install时,出现以下错误:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command C:\Program Files\Git\bin\git.exe --no-replace-objects clone -b v3.5.0 ssh://git@github.com/bigcommerce-labs/node-sass.git C:\Users\saman\AppData\Roaming\npm-cache\_cacache\tmp\git-clonerVR5QJ --recurse-submodules --depth=1 --config core.longpaths=true
npm ERR! fatal: destination path 'C:\Users\saman\AppData\Roaming\npm-cache\_cacache\tmp\git-clonerVR5QJ' already exists and is not an empty directory.

实际该目录为空,但报错提示非空。

已尝试的排查步骤

  • 更换不同版本的Node.js
  • 重新执行完整安装流程
  • 删除Node.js环境变量后重装
  • 检查Git用户名和邮箱配置
  • 执行npm cache clean --force清理缓存
  • 设置npm config set node-sass:git https://github.com/bigcommerce-labs/node-sass.git改用HTTPS克隆
  • 全局更新npm:npm install -g npm
  • 手动删除缓存临时目录C:\Users\saman\AppData\Roaming\npm-cache\_cacache\tmp

解决方案

方案1:彻底清理临时目录并强制重新安装

  1. 以管理员身份打开命令提示符,执行命令彻底删除缓存临时目录:
    rmdir /s /q "C:\Users\saman\AppData\Roaming\npm-cache\_cacache\tmp"
    
  2. 删除项目目录下的node_modules和package-lock.json:
    rmdir /s /q node_modules
    del package-lock.json
    
  3. 重新执行npm install

方案2:绕过Git直接安装预编译二进制包

node-sass v3.5.0版本的Git克隆可能存在兼容性问题,可直接使用预编译二进制包:

  1. 设置node-sass二进制源:
    npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
    
  2. 删除项目下的node_modules和package-lock.json(同方案1步骤2)
  3. 执行npm install

方案3:降级Node.js到兼容版本

node-sass v3.5.0仅兼容Node.js 8.x-12.x版本,当前使用的Node.js 20.x版本过高:

  1. 卸载当前Node.js,安装Node.js 12.x LTS版本
  2. 清理npm缓存:npm cache clean --force
  3. 重新执行npm install

方案4:检查目录权限

Windows权限限制可能导致Git无法识别目录状态:

  1. 右键C:\Users\saman\AppData\Roaming\npm-cache目录 → 属性 → 安全标签
  2. 选择当前登录用户,勾选“完全控制”权限
  3. 应用设置后重新执行安装

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 15:43:13