该应用程序在“开始”之后运行良好'在Windows中,但当我从github拉入Heroku时,我只是得到一个错误。
的package.json:
{
"name": "tic-tac-toe",
"version": "0.1.0",
"dependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4"
},
"engines": {
"node": "6.10.3",
"npm":"3.10.10"
},
"devDependencies": {
"react-scripts": "1.0.7"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
和错误日志:
app[web.1]: npm ERR! npm bugs tic-tac-toe
app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
app[web.1]: npm ERR! npm owner ls tic-tac-toe
app[web.1]: npm ERR! There is likely additional logging output above.
app[web.1]:
app[web.1]: npm ERR! Please include the following file with any support request:
app[web.1]: npm ERR! /app/npm-debug.log
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=react-tac-to.herokuapp.com request_id=c3cf2461-1989-4734-a7d5-157eb81c9643 fwd="24.29.73.46" dyno= connect= service= status=503 bytes= protocol=https
heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=react-tac-to.herokuapp.com request_id=05109629-cbb4-4927-9d13-8a3a37fedb93 fwd="24.29.73.46" dyno= connect= service= status=503 bytes= protocol=https
问题的本质使我认为这是基于配置的,而不是主要的app.js代码。 主文件有点长,所以如果你想看到它,我会在Github上链接到它: https://github.com/owenpercoco/React-Tac-Toe
答案 0 :(得分:15)
我遇到了同样的问题,但是以上解决方案不适用于我在Heroku中的react应用。 我已经将构建包更新为create-react-app,并且对我有用。
heroku buildpacks:set mars/create-react-app
答案 1 :(得分:12)
然后npm i serve
即可安装服务,也可以使用yarn代替npm
您可以在package.json文件中更改脚本,这似乎是由react更新引起的。
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"heroku-postbuild": "npm run build"}
希望它可以解决您的问题。
答案 2 :(得分:4)
我面临同样的问题,它对我有用。
向应用程序添加“服务”。
示例:
npm add serve or yarn add serve
更改package.json中的脚本后
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"heroku-postbuild": "npm run build"
}
答案 3 :(得分:1)
默认情况下,Heroku不会安装devdependencies: Read .mat files in Python。将react-scripts模块设置为始终在Heroku上安装或关闭生产模式。
答案 4 :(得分:0)
1。)npm install serve --save
或yarn install serve --save
在您的终端中
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"
}
2。)在我的package.json文件中复制了上面的代码以代替以前的代码“ scripts”
3。)git commit -am "new update"
4。)git push heroku master