Heroku Node.js错误,代码= H10 desc =“应用程序崩溃”

时间:2019-04-27 13:28:14

标签: node.js heroku

我浏览了很多类似的主题,但到目前为止仍无法解决我的问题。

我创建了一个MERN应用程序,将亚马逊用于我的资产,并尝试将其部署在Heroku上。

我的应用程序在本地运行,但是当我在Heroku上部署它时,出现了“应用程序错误”。 当我查看heroku日志--tail时,这是我得到的最终错误:

2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https

这是完整的日志:

2019-04-27T12:48:09.000000+00:00 app[api]: Build succeeded
2019-04-27T12:48:24.009559+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:27.790744+00:00 app[web.1]:
2019-04-27T12:48:27.790767+00:00 app[web.1]: > joystock@1.0.0 start /app
2019-04-27T12:48:27.790768+00:00 app[web.1]: > node server.js
2019-04-27T12:48:27.790770+00:00 app[web.1]:
2019-04-27T12:48:29.369354+00:00 app[web.1]:
2019-04-27T12:48:29.369392+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:29.369396+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:29.369397+00:00 app[web.1]: ^
2019-04-27T12:48:29.369917+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2019-04-27T12:48:29.369920+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:29.369923+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:29.369925+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:29.369928+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:29.369930+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:29.369932+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:29.369933+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:29.369935+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:29.369936+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:29.369938+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:29.369939+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:29.369942+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:29.430850+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:29.434765+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:29.436805+00:00 app[web.1]: npm ERR! joystock@1.0.0 start: `node server.js`
2019-04-27T12:48:29.437062+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:29.437419+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:29.437721+00:00 app[web.1]: npm ERR! Failed at the joystock@1.0.0 start script.
2019-04-27T12:48:29.438013+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:29.457869+00:00 app[web.1]:
2019-04-27T12:48:29.458356+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:29.458709+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-27T12_48_29_440Z-debug.log
2019-04-27T12:48:29.555420+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:29.559599+00:00 heroku[web.1]: State changed from crashed to starting
2019-04-27T12:48:29.536335+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:48:38.161883+00:00 heroku[web.1]: Starting process with command `npm start`
2019-04-27T12:48:40.468366+00:00 app[web.1]:
2019-04-27T12:48:40.468385+00:00 app[web.1]: > joystock@1.0.0 start /app
2019-04-27T12:48:40.468387+00:00 app[web.1]: > node server.js
2019-04-27T12:48:40.468388+00:00 app[web.1]:
2019-04-27T12:48:41.210741+00:00 app[web.1]:
2019-04-27T12:48:41.210778+00:00 app[web.1]: /app/node_modules/mongoose/lib/connection.js:465
2019-04-27T12:48:41.210781+00:00 app[web.1]: throw new MongooseError('The `uri` parameter to `openUri()` must be a ' +
2019-04-27T12:48:41.210783+00:00 app[web.1]: ^
2019-04-27T12:48:41.211208+00:00 app[web.1]: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
2019-04-27T12:48:41.211212+00:00 app[web.1]: at new MongooseError (/app/node_modules/mongoose/lib/error/mongooseError.js:14:11)
2019-04-27T12:48:41.211214+00:00 app[web.1]: at NativeConnection.Connection.openUri (/app/node_modules/mongoose/lib/connection.js:465:11)
2019-04-27T12:48:41.211216+00:00 app[web.1]: at Mongoose.connect (/app/node_modules/mongoose/lib/index.js:289:15)
2019-04-27T12:48:41.211218+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:25:4)
2019-04-27T12:48:41.211219+00:00 app[web.1]: at Module._compile (module.js:653:30)
2019-04-27T12:48:41.211221+00:00 app[web.1]: at Object.Module._extensions..js (module.js:664:10)
2019-04-27T12:48:41.211222+00:00 app[web.1]: at Module.load (module.js:566:32)
2019-04-27T12:48:41.211224+00:00 app[web.1]: at tryModuleLoad (module.js:506:12)
2019-04-27T12:48:41.211225+00:00 app[web.1]: at Function.Module._load (module.js:498:3)
2019-04-27T12:48:41.211227+00:00 app[web.1]: at Function.Module.runMain (module.js:694:10)
2019-04-27T12:48:41.211228+00:00 app[web.1]: at startup (bootstrap_node.js:204:16)
2019-04-27T12:48:41.211231+00:00 app[web.1]: at bootstrap_node.js:625:3
2019-04-27T12:48:41.220629+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-04-27T12:48:41.221020+00:00 app[web.1]: npm ERR! errno 1
2019-04-27T12:48:41.222262+00:00 app[web.1]: npm ERR! joystock@1.0.0 start: `node server.js`
2019-04-27T12:48:41.222424+00:00 app[web.1]: npm ERR! Exit status 1
2019-04-27T12:48:41.222687+00:00 app[web.1]: npm ERR!
2019-04-27T12:48:41.222855+00:00 app[web.1]: npm ERR! Failed at the joystock@1.0.0 start script.
2019-04-27T12:48:41.223019+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-04-27T12:48:41.228089+00:00 app[web.1]:
2019-04-27T12:48:41.228288+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-04-27T12:48:41.228431+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-04-27T12_48_41_224Z-debug.log
2019-04-27T12:48:41.314693+00:00 heroku[web.1]: State changed from starting to crashed
2019-04-27T12:48:41.291941+00:00 heroku[web.1]: Process exited with status 1
2019-04-27T12:49:01.084214+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-earth-15269.herokuapp.com request_id=b2953cc1-6894-4697-8fc4-17d5012c536e fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https
2019-04-27T12:49:01.622395+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-earth-15269.herokuapp.com request_id=2a9fbdbb-a35d-4ba1-a032-b263110e10db fwd="93.11.10.123" dyno= connect= service= status=503 bytes= protocol=https


我已经尝试过/检查过:

  • 港口
const port = process.env.PORT || 5000;

app.listen(port, () => console.log(`Joystock Server running on port ${port}`));
  • 尝试过: heroku restart

  • 在我的package.json文件中添加引擎版本

"engines": {
    "node": "8.12.0",
    "npm": "6.4.1"
  },
  • 我的配置变量(mongoURI)已在我的此应用程序的heroku设置中正确定义。

  • 我还尝试从头开始完全重新创建该应用程序,并且所有内容都是最新的。

  • 首先,我没有为'/'定义任何路由,因此我尝试在routes/tracks.js

  • 中添加一个路由
router.get('/', (req, res) => {
  res.redirect('/all/page-1');
});

无论是否使用此路由,我都得到相同的结果。

...我总是会遇到相同的错误。


这是我目前用于该应用程序的git仓库: https://github.com/Karaza/joystock


我对下一步如何修复应用程序一无所知。

在此先感谢您的帮助(:

2 个答案:

答案 0 :(得分:0)

在文件中:joystock / config / keys.js ...确保NODE_ENV已投入生产?没有keys_dev文件。

if (process.env.NODE_ENV === 'production') {
    module.exports = require('./keys_prod');
} else {
    module.exports = require('./keys_dev');
}

我对heroku并不熟悉,但是您似乎禁用了生产模式。

"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"

所以我认为需要检查:

process.env.MONGO_URI
process.env.NODE_ENV

答案 1 :(得分:0)

在我的配置变量中,我尝试定义mongoURI而不是MONGO_URI 现在正在工作:)