使用npm install后,Reoku应用程序在Heroku上崩溃

时间:2017-06-30 02:11:05

标签: node.js reactjs heroku deployment npm-install

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

您可以在终端上执行此操作来重现此问题。

create-react-app [项目名称]
cd [项目名称]
git init
heroku git:remote -a [heroku app的名字]
git add。
git commit -m" init"
git push heroku master

你会发现一切正常,但之后再尝试。

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

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

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

注意:在这种情况下,react-react-app已经安装了react-dom,因此npm只会更新它。它仍然崩溃了。您可以安装一个新模块,但它的行为仍然相同。

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

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

2 个答案:

答案 0 :(得分:0)

This sequence of commands should do the trick

npm install -g create-react-app
create-react-app my-app
cd my-app
git init
heroku create -b https://github.com/mars/create-react-app-buildpack.git
git add .
git commit -m "react-create-app on Heroku"
git push heroku master
heroku open

我认为为React(-b https://github.com/mars/create-react-app-buildpack.git)添加自定义buildpack是您所缺少的。在Heroku项目仪表板的设置选项卡下,您可以将buildpack添加到现有项目中。

-b标志是--buildpack

的缩写
$ heroku help create
Usage: heroku create [APP] [flags]

creates a new app

Flags:
 -b, --buildpack  buildpack url to use for this app
 -n, --no-remote  do not create a git remote
 -o, --org        organization to use
 -r, --remote     the git remote to create, default "heroku"
 -s, --stack      the stack to create the app on
 -t, --team       team to use
 --addons         comma-delimited list of addons to install
 --region         specify region for the app to run in
 --space          the private space to create the app in
 --ssh-git        use SSH git protocol for local git remote

这是我计算机上heroku cli的版本:

$ heroku --version
heroku-cli/6.12.0-a504409 (darwin-x64) node-v7.10.0

有关buildpacks命令的特定信息:

$ heroku help buildpacks
Usage: heroku buildpacks [flags]

display the buildpack_url(s) for an app

Flags:
 -a, --app     (required) app to run command against
 -r, --remote  git remote of app to use

Examples:
    $ heroku buildpacks

heroku buildpacks commands: (get help with heroku help buildpacks:COMMAND)
 buildpacks               display the buildpack_url(s) for an app
 buildpacks:add URL       add new app buildpack, inserting into list of buildpacks if necessary
 buildpacks:clear         clear all buildpacks set on the app
 buildpacks:remove [URL]  remove a buildpack set on the app
 buildpacks:set URL       set new app buildpack, overwriting into list of buildpacks if necessary

您可以运行heroku buildpacks:add https://github.com/mars/create-react-app-buildpack.git,而不是通过网络信息中心添加该buildpack。

答案 1 :(得分:0)

经过一些调试后,我发现了root错误。当我在npm安装一个包时,它与构建混乱。模块反应脚本不再起作用了。

我将它从devDependencies移动到package.json中的依赖项,删除了我的节点模块,package-lock.json,并重新安装了所有内容,并且在本地工作。所以,我部署了它,现在一切正常。