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

在Windows执行HOST=localhost npm run start:debug报错的解决咨询

Fixing the HOST=localhost npm run start:debug Error on Windows

Hey there! This is a super common gotcha when switching between macOS/Linux shells and Windows' CMD/PowerShell—they handle temporary environment variables totally differently. Let's get your server running smoothly on both Windows shells.

Why the Original Command Fails

On macOS/Linux, you can prefix a command with VAR=value to set a temporary environment variable just for that one command. But Windows' CMD and PowerShell don't recognize this syntax, which is why you're seeing those "not recognized" errors.

Solution for Windows CMD

In CMD, you need to use the set command to define the environment variable first, then chain the npm command with &&:

set HOST=localhost && npm run start:debug
  • set HOST=localhost sets the temporary environment variable for your current CMD session.
  • && ensures the npm command only runs if the set command succeeds.

Solution for Windows PowerShell

PowerShell uses its own environment variable syntax with $env:. Use this command instead:

$env:HOST="localhost"; npm run start:debug
  • $env:HOST="localhost" sets the temporary variable for your current PowerShell session.
  • The semicolon (;) separates the two commands so they run in sequence.

Bonus: Cross-Platform Alternative (No Shell-Specific Commands!)

If you want to avoid remembering different commands for each system, create a .env file in your project root with this line:

HOST=localhost

Most modern frameworks (like React, Vue, or Node.js projects using dotenv) automatically load variables from .env files. Now you can just run npm run start:debug on any system—no extra environment variable setup needed!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:28:58