繁体   English   中英

在Heroku上部署时,Nodejs应用程序崩溃。 在本地工作

[英]Nodejs App crashes when deploying on Heroku. Works locally

现在,我花了几天的时间寻找发生这种情况的原因,并尝试确保所有文件名在本地和git push中都一致,因为我听说Heroku对此可能很有趣。

该应用程序在我应添加的本地服务器上绝对正常。

这是当我在heroku上重新启动应用程序时来自的heroku日志:

2019-03-04T21:42:46.527650+00:00 heroku[web.1]: State changed from crashed to starting
2019-03-04T21:42:49.314540+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-04T21:42:50.921757+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-04T21:42:50.921775+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-04T21:42:50.921776+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-04T21:42:50.921777+00:00 app[web.1]: DYNO: 'web.1',
2019-03-04T21:42:50.921779+00:00 app[web.1]: PWD: '/app',
2019-03-04T21:42:50.921780+00:00 app[web.1]: HOME: '/app',
2019-03-04T21:42:50.921781+00:00 app[web.1]: PORT: '51817',
2019-03-04T21:42:50.921782+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-04T21:42:50.921783+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-04T21:42:50.921784+00:00 app[web.1]: SHLVL: '1',
2019-03-04T21:42:50.921785+00:00 app[web.1]: PATH:
2019-03-04T21:42:50.921787+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-04T21:42:50.921788+00:00 app[web.1]: PS1:
2019-03-04T21:42:50.921790+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-04T21:42:50.921791+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-04T21:42:50.921792+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-04T21:42:50.921793+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-04T21:42:50.921794+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-04T21:42:50.921795+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-04T21:42:51.723033+00:00 app[web.1]: internal/modules/cjs/loader.js:582
2019-03-04T21:42:51.723058+00:00 app[web.1]: throw err;
2019-03-04T21:42:51.723060+00:00 app[web.1]: ^
2019-03-04T21:42:51.723061+00:00 app[web.1]:
2019-03-04T21:42:51.723063+00:00 app[web.1]: Error: Cannot find module './controllers/createPost'
2019-03-04T21:42:51.723066+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
2019-03-04T21:42:51.723068+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:506:25)
2019-03-04T21:42:51.723069+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:636:17)
2019-03-04T21:42:51.723071+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:20:18)
2019-03-04T21:42:51.723073+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:14:30)
2019-03-04T21:42:51.723074+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2019-03-04T21:42:51.723076+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2019-03-04T21:42:51.723078+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2019-03-04T21:42:51.723079+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2019-03-04T21:42:51.723081+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:529:3)
2019-03-04T21:42:51.723082+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
2019-03-04T21:42:51.723084+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2019-03-04T21:42:51.723086+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
2019-03-04T21:42:51.789482+00:00 heroku[web.1]: State changed from starting to crashed
2019-03-04T21:42:51.770169+00:00 heroku[web.1]: Process exited with status 1
2019-03-04T21:43:12.736446+00:00 heroku[run.9030]: Client connection closed. Sending SIGHUP to all processes
2019-03-04T21:43:13.319723+00:00 heroku[run.9030]: State changed from up to complete
2019-03-04T21:43:13.297680+00:00 heroku[run.9030]: Process exited with status 129
2019-03-04T21:43:16.063306+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=james-node-blog.herokuapp.com request_id=b16a486a-239e-4bc4-9673-4f24febd9265 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https
2019-03-04T21:43:17.018561+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=63cc1508-3943-4251-b424-674186d84e76 fwd="82.6.200.12" dyno= connect= service= status=503 bytes= protocol=https

另外,可以在我的Github存储库中找到以下代码:

https://github.com/jameslevine/Nodejs-Blog

如果有人有任何建议,我将不胜感激,因为我现在要绕圈转。

提前致谢!

更新:解决了2个错误。 第一个是文件名更改,第二个是.gitignore不包含node_modules文件的事实。 现在应用程序给出了该日志,表明它不再崩溃。 但是,通过单击Heroku上的Live App,我仍然看不到该应用程序。 有什么帮助吗?

我包括以下日志:

2019-03-05T08:59:41.441061+00:00 heroku[web.1]: Restarting
2019-03-05T08:59:41.444978+00:00 heroku[web.1]: State changed from up to starting
2019-03-05T08:59:42.400893+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2019-03-05T08:59:42.520869+00:00 heroku[web.1]: Process exited with status 143
2019-03-05T08:59:43.970483+00:00 heroku[web.1]: Starting process with command `node index.js`
2019-03-05T08:59:45.929838+00:00 app[web.1]: { NODE_HOME: '/app/.heroku/node',
2019-03-05T08:59:45.929860+00:00 app[web.1]: NODE_ENV: 'production',
2019-03-05T08:59:45.929862+00:00 app[web.1]: WEB_MEMORY: '512',
2019-03-05T08:59:45.929863+00:00 app[web.1]: DYNO: 'web.1',
2019-03-05T08:59:45.929865+00:00 app[web.1]: PWD: '/app',
2019-03-05T08:59:45.929867+00:00 app[web.1]: HOME: '/app',
2019-03-05T08:59:45.929868+00:00 app[web.1]: PORT: '54093',
2019-03-05T08:59:45.929869+00:00 app[web.1]: MEMORY_AVAILABLE: '512',
2019-03-05T08:59:45.929870+00:00 app[web.1]: WEB_CONCURRENCY: '1',
2019-03-05T08:59:45.929871+00:00 app[web.1]: SHLVL: '1',
2019-03-05T08:59:45.929873+00:00 app[web.1]: PATH:
2019-03-05T08:59:45.929874+00:00 app[web.1]: '/app/.heroku/node/bin:/app/.heroku/yarn/bin:/usr/local/bin:/usr/bin:/bin:/app/bin:/app/node_modules/.bin',
2019-03-05T08:59:45.929875+00:00 app[web.1]: PS1:
2019-03-05T08:59:45.929877+00:00 app[web.1]: '\\[\\033[01;34m\\]\\w\\[\\033[00m\\] \\[\\033[01;32m\\]$ \\[\\033[00m\\]',
2019-03-05T08:59:45.929878+00:00 app[web.1]: _: '/app/.heroku/node/bin/node',
2019-03-05T08:59:45.929879+00:00 app[web.1]: COUDINARY_NAME: 'djbcg1deo',
2019-03-05T08:59:45.929880+00:00 app[web.1]: COUDINARY_API_KEY: '571183338823141',
2019-03-05T08:59:45.929881+00:00 app[web.1]: COUDINARY_API_SECRET: 'DkJ_3UsH7DLTsHHwmD68AMUYJzY',
2019-03-05T08:59:45.929882+00:00 app[web.1]: DB_URI: 'node-js-blog' }
2019-03-05T08:59:46.787139+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined resave option; provide resave option at index.js:38:9
2019-03-05T08:59:46.787355+00:00 app[web.1]: Tue, 05 Mar 2019 08:59:46 GMT express-session deprecated undefined saveUninitialized option; provide saveUninitialized option at index.js:38:9
2019-03-05T08:59:46.795789+00:00 app[web.1]: (node:4) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2019-03-05T08:59:46.796700+00:00 app[web.1]: App listing on port 54093
2019-03-05T08:59:46.804363+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
2019-03-05T08:59:46.804367+00:00 app[web.1]: at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:564:11)
2019-03-05T08:59:46.804369+00:00 app[web.1]: at Pool.emit (events.js:182:13)
2019-03-05T08:59:46.804370+00:00 app[web.1]: at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:317:12)
2019-03-05T08:59:46.804372+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804373+00:00 app[web.1]: at Connection.emit (events.js:182:13)
2019-03-05T08:59:46.804375+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:246:50)
2019-03-05T08:59:46.804377+00:00 app[web.1]: at Object.onceWrapper (events.js:273:13)
2019-03-05T08:59:46.804378+00:00 app[web.1]: at Socket.emit (events.js:182:13)
2019-03-05T08:59:46.804380+00:00 app[web.1]: at emitErrorNT (internal/streams/destroy.js:82:8)
2019-03-05T08:59:46.804382+00:00 app[web.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
2019-03-05T08:59:46.804384+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-03-05T08:59:46.804474+00:00 app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
2019-03-05T08:59:46.804552+00:00 app[web.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2019-03-05T08:59:47.581487+00:00 heroku[web.1]: State changed from starting to up
2019-03-05T09:00:21.698023+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=james-node-blog.herokuapp.com request_id=55c8cc21-6544-4e4c-800f-62eac6ed8034 fwd="62.30.226.42" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 protocol=https
2019-03-05T09:01:18.887286+00:00 heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/favicon.ico" host=james-node-blog.herokuapp.com request_id=ccfeba5b-3105-423c-87f6-edfe9ba86584 fwd="62.30.226.42" dyno=web.1 connect=1ms service=55036ms status=503 bytes= protocol=https

有什么想法为什么现在没有实时显示? 我才刚刚开始对此进行研究,并认为这与服务器未启动有关,但我认为我会随着进展而更新。

我认为这只是一个错字,您正在尝试在index.js:14中要求createPost ,而该文件实际上称为createpost.js

Error: Cannot find module './controllers/createPost'

不过,它在本地工作很奇怪。

暂无
暂无

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

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