将Express.js + React.js项目部署到heroku时出错

时间:2020-10-09 15:57:21

标签: node.js reactjs postgresql express heroku

我在网站上完成工作后,在本地一切正常,但是部署到heroku时出现错误。

某些背景:

部署问题

现在,为了进行部署,我使用了https://www.freecodecamp.org/news/deploy-a-react-node-app-to/上的教程,并在heroku上创建了一个新的Postgres数据库(就是这样)。 当我尝试查看“ xxxxx.herokuapp.com”上的站点时,此“应用程序错误”消息:

enter image description here

所以我尝试运行heroku logs --tail命令,这是我收到的消息:

heroku logs --tail -a grades-il

2020-10-09T15:26:15.091358+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-09T15:26:17.586004+00:00 heroku[web.1]: Process exited with status 1
2020-10-09T15:26:17.623057+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-09T15:26:17.333545+00:00 app[web.1]:
2020-10-09T15:26:17.333566+00:00 app[web.1]: > node-sequelize@0.0.0 start /app
2020-10-09T15:26:17.333567+00:00 app[web.1]: > node ./bin/www
2020-10-09T15:26:17.333567+00:00 app[web.1]:
2020-10-09T15:26:17.505070+00:00 app[web.1]: internal/modules/cjs/loader.js:834
2020-10-09T15:26:17.505072+00:00 app[web.1]: throw err;
2020-10-09T15:26:17.505072+00:00 app[web.1]: ^
2020-10-09T15:26:17.505072+00:00 app[web.1]:
2020-10-09T15:26:17.505073+00:00 app[web.1]: Error: Cannot find module './school'
2020-10-09T15:26:17.505073+00:00 app[web.1]: Require stack:
2020-10-09T15:26:17.505073+00:00 app[web.1]: - /app/controllers/index.js
2020-10-09T15:26:17.505074+00:00 app[web.1]: - /app/routes/index.js
2020-10-09T15:26:17.505074+00:00 app[web.1]: - /app/app.js
2020-10-09T15:26:17.505074+00:00 app[web.1]: - /app/bin/www
2020-10-09T15:26:17.505075+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
2020-10-09T15:26:17.505075+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:687:27)
2020-10-09T15:26:17.505075+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19)
2020-10-09T15:26:17.505075+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-10-09T15:26:17.505076+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/index.js:1:16)
2020-10-09T15:26:17.505076+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-10-09T15:26:17.505076+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-10-09T15:26:17.505076+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-10-09T15:26:17.505077+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-10-09T15:26:17.505077+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:903:19) {
2020-10-09T15:26:17.505077+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-10-09T15:26:17.505077+00:00 app[web.1]: requireStack: [
2020-10-09T15:26:17.505078+00:00 app[web.1]: '/app/controllers/index.js',
2020-10-09T15:26:17.505078+00:00 app[web.1]: '/app/routes/index.js',
2020-10-09T15:26:17.505078+00:00 app[web.1]: '/app/app.js',
2020-10-09T15:26:17.505079+00:00 app[web.1]: '/app/bin/www'
2020-10-09T15:26:17.505079+00:00 app[web.1]: ]
2020-10-09T15:26:17.505079+00:00 app[web.1]: }
2020-10-09T15:26:17.515720+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-10-09T15:26:17.515920+00:00 app[web.1]: npm ERR! errno 1
2020-10-09T15:26:17.520600+00:00 app[web.1]: npm ERR! node-sequelize@0.0.0 start: `node ./bin/www`
2020-10-09T15:26:17.520705+00:00 app[web.1]: npm ERR! Exit status 1
2020-10-09T15:26:17.520815+00:00 app[web.1]: npm ERR!
2020-10-09T15:26:17.520929+00:00 app[web.1]: npm ERR! Failed at the node-sequelize@0.0.0 start script.
2020-10-09T15:26:17.521011+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-09T15:26:17.525367+00:00 app[web.1]:
2020-10-09T15:26:17.525509+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-10-09T15:26:17.525583+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-10-09T15_26_17_521Z-debug.log
2020-10-09T15:27:20.340920+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=xxxxx.herokuapp.com request_id=320b7a37-e1e9-4974-92b0-b98e6af2667a fwd="79.177.39.29" dyno= connect= service= status=503 bytes= protocol=http
2020-10-09T15:27:20.850485+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=xxxxx.herokuapp.com request_id=23268c05-28cf-4fc4-9aa7-8ef69befa2b2 fwd="79.177.39.29" dyno= connect= service= status=503 bytes= protocol=http

因此,如果您有任何解决方法的想法,我们将不胜感激。 谢谢!

1 个答案:

答案 0 :(得分:0)

感谢Mohit Karekar,我只需更改即可解决问题

require('./school');

require('./School');

就是这样。