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

运行npm run dev或npm run build时出现bash脚本命令未找到错误的求助

解决npm run dev/build时的"D:Temp...sh: command not found"错误

Hey there, let's work through this error you're hitting! The error /usr/bin/bash: D:Tempdev-1656515078305.sh: command not found points to a path parsing conflict between Windows-style file paths and Unix-like shell environments (like Git Bash or WSL). Here's how to fix it:

核心原因

Your terminal is trying to interpret a Windows temporary file path (like D:\Temp\dev-xxxx.sh) using a bash shell, which doesn't recognize the D:Temp format — bash expects /mnt/d/Temp/... for WSL, or proper Windows path syntax for native terminals like Command Prompt/PowerShell.

分步解决方案

1. 切换到适配的终端环境

  • If you’re using Git Bash or WSL, try running commands in Windows’ native Command Prompt or PowerShell instead. These environments handle Windows paths natively without parsing errors.
  • If you need to use WSL, move your project to the WSL filesystem (e.g., /home/your-username/your-project) instead of a mounted Windows drive (/mnt/d/...). Cross-filesystem script execution often causes path misinterpretation.

2. 清理npm缓存并重装依赖

Corrupted cached files might be causing odd path glitches. Run these commands in order:

npm cache clean --force
rm -rf node_modules package-lock.json
npm install

Then test npm run dev again.

3. 修复文件换行符

Windows uses CRLF line endings, while Unix shells prefer LF. If your project was created on Windows and run in a bash environment, mismatched line endings can break script execution:

  • In VS Code, open your package.json, click the CRLF/LF indicator in the bottom-right corner, and switch to LF.
  • If you have dos2unix available in your shell, convert the file directly:
    dos2unix package.json
    

4. 直接测试Next.js命令

Skip the npm script temporarily to rule out script-related issues. Run:

npx next dev

If this works, the problem is likely tied to how npm generates temporary scripts in your environment.

确认你的环境信息

Just to recap what you shared:

  • Node.js version: v16.14.2
  • npm version: 8.13.1
  • Relevant package.json scripts:
    {
      "scripts": {
        "dev": "next",
        "build": "next build",
        "start": "next start",
        "type-check": "tsc"
      }
    }
    

Give these steps a try, and let me know if you still run into issues!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 01:08:13