每当我npm安装任何模块时,我的ReactJS应用程序总是崩溃。
您可以通过在终端上执行此操作来重现问题。
创建react应用程序[项目名称]
cd[项目名称]
git init
heroku git:remote-一个[heroku应用程序名称]
git add
git提交-m“init”
git推送主机
你会发现一切都很好,但以后再试试这个。
npm安装react dom
(或任何包/模块。使用--save也会产生相同的错误)
git add-u
git提交-m"新模块"
git推送heroku master
应用程序会在服务器上崩溃,我不知道为什么。
注意:在这种情况下,CreateReact应用程序已经安装了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
这个命令序列应该可以做到:
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)添加定制的buildpackhttps://github.com/mars/create-react-app-buildpack.git
)是您所缺少的。在Heroku项目仪表板的“设置”选项卡下,可以将构建包添加到现有项目中。
-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:addhttps://github.com/mars/create-react-app-buildpack.git而不是通过web仪表板添加构建包。
经过一些调试,我发现根错误。当我npm安装一个包时,它弄乱了构建。模块反应脚本不再工作了。
我将它从devdependency移动到包中的dependency。json,删除了我的节点模块,包锁。json,并重新安装了所有内容,并且在本地运行。所以,我部署了它,现在一切正常。