使用npm install后React应用在Heroku上崩溃 [英] React app crashes on Heroku after using npm install

查看:106
本文介绍了使用npm install后React应用在Heroku上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我npm安装任何模块时,我的ReactJS应用程序总是崩溃.

My ReactJS app always crashes whenever I npm install any module.

您可以通过在终端上执行此操作来重现该问题.

You can reproduce the problem by doing this on the terminal.

create-react-app [项目名称]
cd [项目名称]
git init
heroku git:远程-a [heroku应用程序的名称]
git add.
git commit -m"init"
git push heroku master

create-react-app [name of project]
cd [name of project]
git init
heroku git:remote -a [name of heroku app]
git add .
git commit -m "init"
git push heroku master

您会看到一切正常,但是请稍后再试.

You will see that everything works fine, but try this afterwards.

npm install react-dom
(或任何软件包/模块.使用--save也会产生相同的错误)

npm install react-dom
(or any package/modules. Using --save also produces the same error)

git add -u
git commit -m新模块"
git push heroku master

git add -u
git commit -m "new module"
git push heroku master

该应用程序将在服务器上崩溃,我不知道为什么.

The app will crash on the server and I don't know why.

注意:在这种情况下,create-react-app已经安装了react-dom,因此npm仅对其进行更新.尽管如此,它还是崩溃了.您可以安装一个新模块,它的行为仍然相同.

Note: In this case, react-dom was already installed by create-react-app, so npm only updates it. Still, it crashes. You can install a new module, and it will still behave the same.

根据要求,以下是错误日志.

As requested, here are the error logs.

2017-06-30T20:12:46.778184+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-06-30T20:12:46.778396+00:00 app[web.1]: npm ERR! 
2017-06-30T20:12:46.778645+00:00 app[web.1]: npm ERR! Failed at the 007-test@0.1.0 start script.
2017-06-30T20:12:46.779136+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-06-30T20:12:46.780482+00:00 app[web.1]: 
2017-06-30T20:12:46.780763+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-06-30T20:12:46.780934+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-06-30T20_12_46_768Z-debug.log
2017-06-30T20:12:46.920375+00:00 heroku[web.1]: State changed from starting to crashed
2017-06-30T20:12:46.903436+00:00 heroku[web.1]: Process exited with status 1
2017-06-30T21:01:33.667285+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=react-app-007.herokuapp.com request_id=d4936b9c-4c21-4ce4-862c-8b05da3bc005 fwd="64.62.224.29" dyno= connect= service= status=503 bytes= protocol=https
2017-06-30T21:01:35.111452+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=react-app-007.herokuapp.com request_id=cef9f3f8-a46b-4760-9c24-de59ba540e2e fwd="64.62.224.29" dyno= connect= service= status=503 bytes= protocol=https

推荐答案

经过一些调试,我发现了根本错误.当我npm安装软件包时,它使构建混乱.模块react-scripts不再起作用.

After some debugging, I found the root error. When I npm installed a package, it messed with the build. The module react-scripts wasn't working anymore.

我将其从devDependencies移到package.json中的依赖项,删除了我的节点模块package-lock.json,然后重新安装了所有东西,并且在本地运行.因此,我进行了部署,现在一切正常.

I moved it from devDependencies to dependencies in package.json, removed my node modules, package-lock.json, and reinstalled everything, and that worked locally. So, I deployed it, and everything works fine now.

这篇关于使用npm install后React应用在Heroku上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆