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

在VSCode中执行npm start启动React项目时出现PowerShell ENOENT错误

解决React项目npm start时的"spawn powershell ENOENT"错误

执行npm start启动React开发服务器时出现以下错误:

启动开发服务器...

node:events:492
      throw er; // 未处理的 'error' 事件
      ^

错误: spawn C:\Windows\System32\WindowsPowerShell\v1.0\powershell ENOENT
    在 ChildProcess._handle.onexit (node:internal/child_process:286:19)
    在 onErrorNT (node:internal/child_process:484:16)
    在 process.processTicksAndRejections (node:internal/process/task_queues:82:21)
在 ChildProcess实例上触发 'error' 事件:
    在 ChildProcess._handle.onexit (node:internal/child_process:292:12)
    在 onErrorNT (node:internal/child_process:484:16)
    在 process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell',
  path: 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBoAHQAdABwADoALwAvAGwAbwBjAGEAbABoAG8AcwB0ADoAMwAwADAAMAAiAA=='
  ]
}

解决方案

  • 验证PowerShell路径完整性
    手动访问C:\Windows\System32\WindowsPowerShell\v1.0\目录,确认powershell.exe文件存在。如果缺失,需重新安装Windows PowerShell(Win10/Win11默认预装,若路径被篡改可通过系统修复工具恢复)。

  • 配置系统环境变量
    确保PowerShell路径已加入系统PATH:

    1. 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
    2. 在系统变量的Path列表中,添加C:\Windows\System32\WindowsPowerShell\v1.0\(若未存在)
    3. 重启VS Code和终端,再次执行npm start
  • 强制npm使用cmd作为脚本shell
    若路径正常仍报错,可切换npm默认脚本执行shell为cmd:

    npm config set script-shell "cmd.exe"
    

    执行后重新启动项目。

  • 重装项目依赖
    尝试清理并重新安装依赖,修复可能的子进程调用异常:

    1. 删除项目根目录的node_modules文件夹和package-lock.json文件
    2. 运行npm install重新安装所有依赖
    3. 执行npm start启动项目

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 11:15:10