为什么 npm start 会抛出 events.js:187 throw er; // 我的react项目中未处理的“错误”事件?

IT技术 node.js reactjs npm
2021-04-10 02:13:07

在代码检出后第一次启动服务器时,我的 react js 项目抛出错误“events.js:187 throw er; // Unhandled 'error' event”。我有节点 12.13.0 和 npm 6.12.0 。日志文件附加日志文件

events.js:187
      throw er; // Unhandled 'error' event
      ^



    Error: spawn cmd ENOENT
        at Process.ChildProcess._handle.onexit 
       (internal/child_process.js:264:19)
       at onErrorNT (internal/child_process.js:456:16)
       at processTicksAndRejections (internal/process/task_queues.js:80:21)
    Emitted 'error' event on ChildProcess instance at:
       at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
       at onErrorNT (internal/child_process.js:456:16)
       at processTicksAndRejections (internal/process/task_queues.js:80:21) {
    errno: 'ENOENT',
    code: 'ENOENT',
    syscall: 'spawn cmd',
    path: 'cmd',
    spawnargs: [ '/c', 'start', '""', '/b', 'http://localhost:3000/' ]
}
6个回答

如果你的系统是windows,设置你的环境变量,添加%SystemRoot%\system32到你的PATH我昨天遇到了这个错误,希望它对你有用。不要忘记重启你的电脑

如果以上答案都没有解决您,请尝试此操作.. 转到我的电脑>属性>高级并在环境变量中编辑 PATH 并添加以下内容

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; C:\Program Files\nodejs;C:\Users{yourName}\AppData\Roaming\npm

添加其中的 4 个并重新启动您的 PC

react-script 版本从 3.0.1降级到 2.1.8对我有用依次执行以下命令:- npm install react-scripts@2.1.8 npm install npm start

您可以使用node Your_File_Name.js命令从本地主机运行。要使用 npm start 命令,您需要在 package.json 文件中使用 scripts 数组 "scripts": { "start": "http://localhost:3000/" } 如果这没有帮助,您能否附上更多详细信息?

react-scripts在依赖项数组中没有看到 的依赖项您可以使用该命令npm install react-scripts --save
2021-05-25 02:13:07
你也可以附上 package.json 文件吗
2021-06-08 02:13:07

尝试执行 export PATH=$PATH:/mnt/c/Windows/System32将路径更改为/mnt/c/安装在 wsl Windows 上的路径(mount)。

如果有效,请将路径/mnt/c/Windows/System32插入文件中/etc/environment

在我的情况下,此解决方案有效