at = error code = H10 desc =“App crashed”method = GET path =“/”错误将React / Node部署到Heroku

时间:2018-02-11 00:22:14

标签: json node.js reactjs heroku

我正在尝试部署我正在研究的React on Node项目,并且遇到了一些问题,我不确定为什么。以下是从日志中提取的一些信息:

2018-02-11T00:12:22.875338+00:00 app[web.1]: > dmdb@1.0.0 start /app
2018-02-11T00:12:22.875340+00:00 app[web.1]: > node server.js
2018-02-11T00:12:22.875341+00:00 app[web.1]: 
2018-02-11T00:12:23.315310+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-11T00:12:23.299113+00:00 heroku[web.1]: Process exited with status 1
2018-02-11T00:13:23.976931+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dmdb1.herokuapp.com request_id=8d37e10b-6999-4a2f-82bb-f3e724bf1c4e fwd="108.14.98.161" dyno= connect= service= status=503 bytes= protocol=https

根据日志显示的内容,我的package.json文件中的启动脚本似乎存在问题,但我不确定为什么因为我已经使用类似的另一个项目我已成功部署。我对此做了一些研究,我相信我的Server.js文件已配置且端口设置正确,我删除了devdependencies并确认它在本地工作但未部署,并且我已经在vars中设置了我的SECRET_KEY有auth设置。下面是我如何设置端口,以及我的package.json文件在后端的样子。如果有人能提供一些见解我会非常感激。如果我能提供任何其他信息,请告诉我,我会尽快这样做。

来自Server.js的端口:

//app listening on port 1337
const PORT = process.env.PORT || 1337;
app.listen(PORT, () => {
    console.log(`LISTENING ON PORT ${PORT}`)
})

从Backside更新了Package.json:

{
  "name": "dmdb",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js",
    "dev": "nodemon server.js",
    "debugger": "DEBUG=*:* nodemon server.js",
    "prod": "NODE_ENV=production node server.js",
    "deploy": "cd client && yarn build && cp -a ./build/ ../public/",
    "heroku-postbuid" : "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
  },
  "engines": {
    "node": "8.5.0",
    "yarn": "1.3.2"
  },  
  "author": "Dan Levenson",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.2",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "dotenv": "^4.0.0",
    "ejs": "^2.5.7",
    "ejs-lint": "^0.3.0",
    "express": "^4.16.2",
    "express-session": "^1.15.6",
    "isomorphic-fetch": "^2.2.1",
    "method-override": "^2.3.10",
    "morgan": "^1.9.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "pg-promise": "^7.0.3"
  }
}

提前致谢!

编辑帖子以包含来自客户端的Package.JSON:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.0",
    "reactstrap": "^5.0.0-beta"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:3001"
}

添加构建日志:

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  8.5.0
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  1.3.2

       Resolving node version 8.5.0...
       Downloading and installing node 8.5.0...
       Using default npm version: 5.3.0
       Resolving yarn version 1.3.2...
       Downloading and installing yarn (1.3.2)...
       Installed yarn 1.3.2
-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules
       - bower_components (not cached - skipping)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.3.2
       [1/4] Resolving packages...
       success Already up-to-date.
       Done in 0.30s.
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Build succeeded!
-----> Discovering process types
       Procfile declares types -> web
-----> Compressing...
       Done: 20.7M
-----> Launching...
       Released v12
       https://dmdb-1.herokuapp.com/ deployed to Heroku

2 个答案:

答案 0 :(得分:0)

使用NPM而不是Yarn重建应用程序并且它没有问题地部署并且现在运行良好。谢谢你的帮助!

答案 1 :(得分:0)

此解决方案适用于 GO

通过 heroku 部署应用程序时,不允许是您指定端口号的原因。 换句话说,您不能将Web服务的端口号指定为 8000 或其他名称,heroku会在运行时确定端口号。
因此,您不能使用以下代码:

    log.Fatal(http.ListenAndServe(":8000", router))

您可以做的是获取heroku的运行时端口。
简而言之,只需使用以下代码

    log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))