如何修复('throw er;//未处理的'错误'事件')代码生命周期? [英] How can I fix ('throw er; // Unhandled 'error' event') code lifecycle?
问题描述
我试图创建一个React应用.我使用了命令提示符,但是在创建应用后,当我尝试启动npm时,它给了我一些错误.
I tried to create a React app. I used the command prompt but after the app was created when I tried to start the npm it gives me some errors.
我也尝试在WebStorm,IntelliJ和Visual Studio Code/PowerShell中创建React应用,但仍然给出了同一组错误.
这是我得到的错误:
我尝试了很多事情,例如清理npm缓存,重新安装npm和节点,将npm升级到新版本,尝试升级react,但没有任何效果.
I tried many things like cleaning the npm cache, reinstalling npm and node, upgrading npm to new versions, tried to upgrade react but nothing worked.
events.js:173
throw er; // Unhandled 'error' event
npm ERR! code ELIFECYCLE
npm ERR! errno 1
gives some errors :
events.js:173
throw er; // Unhandled 'error' event
^
但是它应该启动npm并给localhost 3000
but it should start the npm and giving the localhost 3000
推荐答案
- 检查您的节点版本.更新节点和npm
- 如果您使用的是macOS或linux,请尝试
sudo npm start
- 尝试再次下载create-react-app
npm i -g create-react-app
- 尝试在另一个文件夹中创建应用
create-react-app APPNAME
- 仍然无法正常工作吗?然后删除
node_module
文件夹,package-lock.json
并运行npm install
- 尝试在另一个PORT上运行
- Check your node version. update node & npm
- Try
sudo npm start
if you are in macOS or linux - Try to download create-react-app again
npm i -g create-react-app
- Try to create the app in another folder
create-react-app APPNAME
- Still not working? Then delete
node_module
folder,package-lock.json
and runnpm install
- Try to run on another PORT
更新
react-script
版本也可能存在问题.您可以尝试降级react脚本,
Also there can be have a problem with react-script
version. You can try to downgrade the react script,
create-react-app my-app
cd my-app
npm install react-scripts@2.1.8
npm start
此外,请确保您在 PATH
环境变量中具有此条目.
Also, make sure you have this entry in your PATH
environment variable.
C:\ Users \ {用户名} \ AppData \ Roaming \ npm
这篇关于如何修复('throw er;//未处理的'错误'事件')代码生命周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!