Heroku Node.js错误,代码=H10,描述="应用程序崩溃"。

3

我翻了很多类似的主题,但至今无法解决我的问题。

我创建了一个MERN应用程序,使用了亚马逊作为我的资产,并尝试在Heroku上部署它。

我的应用程序在本地工作正常,但当我在Heroku上部署它时,出现了“应用程序错误”。 当我查看heroku logs --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
我已经没有想要尝试修复我的应用程序的想法了。
提前感谢您的帮助(:

我认为这部分已经很容易理解了:确保mongoose.connect()mongoose.createConnection()的第一个参数是一个字符串。 - Lissy93
2个回答

0

在文件:joystock/config/keys.js 中... 确保 NODE_ENV 是 production?没有 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

文件“keys_dev.js”存在,我只是没有将其推送到git,因为我不想显示我的mongoDB URI。 “NPM_CONFIG_PRODUCTION=false”应该只影响devdependecies的安装(更多信息请参见:https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process) - Kara
@Kara,无论如何,我认为需要在server.js中记录“db”,看起来它是未定义的。 - Tim Times
哦天啊...就是这个问题...我在Heroku的变量设置中打成了mongoURI而不是MONGO_URI! 现在它可以工作了 (: - Kara

0
在我的配置变量中,我尝试定义mongoURI而不是MONGO_URI。 现在它可以工作了 :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接