简体   繁体   English

at =错误代码= H10 desc =“应用程序崩溃”方法=获取路径=“ /”将React / Node部署到Heroku时出错

[英]at=error code=H10 desc=“App crashed” method=GET path=“/” Error Deploying React/Node to Heroku

I'm trying to deploy a React on Node project I was working on and am running into some issues and I'm not certain why. 我正在尝试部署一个我正在从事的React on Node项目,并且遇到了一些问题,但我不确定为什么。 Below is some information pulled from the log: 以下是从日志中提取的一些信息:

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

Based on what the log shows, it seems like there's an issue with the start script in my package.json file, but I'm not sure why since I've used a similar one for another project I've deployed successfully. 根据日志显示,package.json文件中的启动脚本似乎存在问题,但是我不确定为什么会用到类似的代码,因为我已经对成功部署的另一个项目使用了类似的脚本。 I did some research on this and I believe my Server.js file is configured and the ports are set up properly, I removed devdependencies and confirmed it works locally but not deployed, and I've got my SECRET_KEY set up in the vars since this has auth set up. 我对此进行了一些研究,我相信我的Server.js文件已配置并且端口设置正确,我删除了依赖关系并确认它在本地有效但未部署,并且自此以来,我已经在vars中设置了SECRET_KEY已设置身份验证。 Below is how I have my ports set up, and what my package.json file looks like on the backend. 以下是我如何设置端口以及后端上的package.json文件的外观。 If anybody could please provide some insight I'd greatly appreciate it. 如果有人可以提供一些见识,我将不胜感激。 If there's any additional information I can provide please let me know and I'll do so ASAP. 如果我可以提供其他任何信息,请告诉我,我会尽快处理。

Ports from Server.js: 来自Server.js的端口:

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

Updated Package.json from 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"
  }
}

Thanks in advance! 提前致谢!

Editing post to include Package.JSON from client: 编辑帖子以包括来自客户端的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"
}

Adding Build Log: 添加构建日志:

-----> 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

Rebuilt app using NPM instead of Yarn and it deployed without issue and is running fine now. 使用NPM而不是Yarn重建了应用程序,并且部署没有问题,并且现在运行良好。 Thanks for the help! 谢谢您的帮助!

THIS SOLUTION IS FOR GO . 此解决方案是可行的

When you deploy an app through heroku , it does not allow you to specify the port number . 通过heroku部署应用程序时,它不允许您指定端口号
In other words, you can not specify your web service's port number as 8000 or something else, heroku decides the port number in runtime. 换句话说,您不能将Web服务的端口号指定为8000或其他名称,heroku在运行时确定端口号。
so, you can not use the following code: 因此,您不能使用以下代码:

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

What you can do is, getting the runtime port of heroku. 您可以做的是获取heroku的运行时端口。
In short, just use the following code : 简而言之, 只需使用以下代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM