npm start error with create-react-app的错误称为-ELIFECYCLE

时间:2019-04-25 17:25:33

标签: reactjs

我正在学习ReactJs课程,同时使用window-7中的命令创建FirstReactApp。

npm install -g create-react-app 
npm create-react-app

这两个代码都可以正常工作,但是当我尝试使用npm start启动服务器时,我得到了一个名为

的错误
  

优雅

下面是我遇到的错误。

C:\my-react-app>npm start

> my-react-app@0.1.0 start C:\my-react-app
> react-scripts start

Starting the development server...

events.js:174
      throw er; // Unhandled 'error' event
      ^enter code here

Error: spawn cmd ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-react-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-react-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm- ERR! A complete log of this run can be found in:

4 个答案:

答案 0 :(得分:3)

几天前我遇到了这个问题。尝试运行这些命令

npm install react-scripts@2.1.8
npm start

答案 1 :(得分:1)

我遇到了同样的问题,并且在敲了一下头之后才发现了问题所在。 这是一个非常简单的修复。

您只需要在项目的package.json文件中将react-scripts的版本更改为2.1.8

如果您不了解,请执行以下婴儿步骤:P。

1打开文件package.json

此文件位于您的项目文件夹中。如果使用的是VSCode之类的编辑器,则可以使用它来查看此文件。

2更改react-scripts版本

在package.json内部,您将看到依赖项块。

  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.0"
  },

现在,我们拥有最新版本3.0.0。我想这才是真正的罪魁祸首。

将其更改为2.1.8。查看我项目的图像快照。

enter image description here

3再次运行npm install并尝试npm start

现在它可以工作了。我不知道为什么3.0.0版引起了问题。但是目前,我认为这里存在一些错误,或者可能还有我不知道的其他任何错误。

可能是其他问题,还有更具体的问题。但是到目前为止,我只是想出了这一点。

希望这对您有所帮助。谢谢:)

答案 2 :(得分:0)

您应该在启动应用程序之前安装节点模块。运行npm installnpm i,然后重试。

答案 3 :(得分:0)

首先卸载现有的npm软件包:

npm uninstall -g create-react-app (-g if you installed globally)

第二:

npm cache clean --force

再次执行此操作:

npm install -g create-react-app@latest and create-react-app my-app
相关问题