用create-react-app运行npm start时出现一个名为-ELIFECYCLE的错误

5

我正在学习ReactJs课程,在Windows 7中使用命令创建FirstReactApp。

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

这两个代码都可以正常工作,但当我尝试使用npm start启动服务器时,遇到了一个名为ELiFECYLE的错误。以下是我收到的错误信息:
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个回答

5

我曾遇到同样的问题,经过一番努力,我找到了解决方法。这是一个非常简单的修复。

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

如果你不理解,可以按照以下步骤操作:

1 打开package.json文件

该文件位于你的项目文件夹内。如果你使用VSCode等编辑器,则可以用它来查看此文件。

2 更改react-scripts版本

在package.json中,你会看到dependencies块。

  "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版本为什么会出问题。但目前我认为可能存在某些错误或其他未知因素。

也许问题还有其他方面和更具体的情况。但迄今为止我只发现了这个问题。

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


3

我几天前也遇到了这个问题。尝试运行以下命令:

npm install react-scripts@2.1.8
npm start

首先运行 npm install react-scripts@2.1.8,"然后"运行 npm start。 - M.Mobark

0

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


首先,我使用以下命令安装了节点模块: npm install -g create-react-app。然后,我创建了一个项目文件夹,并命名为:npx create-react-app my-app。现在,一切都运行得很好,这意味着节点模块已经被创建并存储在my-app文件夹中。最后,我使用以下命令启动服务器: c:/ my-app> npm start。但是,在此最后一步中,我遇到了一个错误。 - Asif Ahmad
@AsifAhmad 尝试运行 npm cache clean --force 命令,然后使用 npx create-react-app xyz 创建一个新的应用程序。 - Nikita Iskorkin
@NikitaIskorkin......我已经执行了您给出的命令,但仍然显示相同的错误。 - Asif Ahmad

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接