【问题标题】:Node.JS app crash on startup after second deployment on Heroku在 Heroku 上进行第二次部署后,Node.JS 应用程序在启动时崩溃
【发布时间】:2021-04-09 15:18:56
【问题描述】:

我第二次做了git push heroku master。 但我收到了错误cannot find module ...。 第一次,我成功了。

我该如何解决这个问题?谢谢。

    2021-01-03T16:03:35.301824+00:00 app[web.1]: internal/modules/cjs/loader.js:818
    2021-01-03T16:03:35.301837+00:00 app[web.1]: throw err;
    2021-01-03T16:03:35.301837+00:00 app[web.1]: ^
    2021-01-03T16:03:35.301837+00:00 app[web.1]:
    2021-01-03T16:03:35.301838+00:00 app[web.1]: Error: Cannot find module './stringToParts'
    2021-01-03T16:03:35.301838+00:00 app[web.1]: Require stack:
    2021-01-03T16:03:35.301839+00:00 app[web.1]: - /app/node_modules/mpath/lib/index.js
    2021-01-03T16:03:35.301839+00:00 app[web.1]: - /app/node_modules/mpath/index.js
    2021-01-03T16:03:35.301839+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
    2021-01-03T16:03:35.301840+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
    2021-01-03T16:03:35.301841+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
    2021-01-03T16:03:35.301841+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
    2021-01-03T16:03:35.301841+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
    2021-01-03T16:03:35.301842+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
    2021-01-03T16:03:35.301842+00:00 app[web.1]: - /app/models/user.js
    2021-01-03T16:03:35.301843+00:00 app[web.1]: - /app/controllers/usersController.js
    2021-01-03T16:03:35.301843+00:00 app[web.1]: - /app/routes/userRoutes.js
    2021-01-03T16:03:35.301844+00:00 app[web.1]: - /app/routes/index.js
    2021-01-03T16:03:35.301845+00:00 app[web.1]: - /app/main.js
    2021-01-03T16:03:35.301845+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    2021-01-03T16:03:35.301846+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    2021-01-03T16:03:35.301846+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
    2021-01-03T16:03:35.301847+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
    2021-01-03T16:03:35.301847+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mpath/lib/index.js:1:21)
    2021-01-03T16:03:35.301848+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
    2021-01-03T16:03:35.301848+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    2021-01-03T16:03:35.301849+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
    2021-01-03T16:03:35.301849+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    2021-01-03T16:03:35.301849+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19) {
    2021-01-03T16:03:35.301850+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
    2021-01-03T16:03:35.301850+00:00 app[web.1]: requireStack: [
    2021-01-03T16:03:35.301851+00:00 app[web.1]: '/app/node_modules/mpath/lib/index.js',
    2021-01-03T16:03:35.301851+00:00 app[web.1]: '/app/node_modules/mpath/index.js',
    2021-01-03T16:03:35.301851+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
    2021-01-03T16:03:35.301852+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
    2021-01-03T16:03:35.301852+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
    2021-01-03T16:03:35.301852+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
    2021-01-03T16:03:35.301853+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
    2021-01-03T16:03:35.301853+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
    2021-01-03T16:03:35.301853+00:00 app[web.1]: '/app/models/user.js',
    2021-01-03T16:03:35.301854+00:00 app[web.1]: '/app/controllers/usersController.js',
    2021-01-03T16:03:35.301854+00:00 app[web.1]: '/app/routes/userRoutes.js',
    2021-01-03T16:03:35.301855+00:00 app[web.1]: '/app/routes/index.js',
    2021-01-03T16:03:35.301855+00:00 app[web.1]: '/app/main.js'
    2021-01-03T16:03:35.301855+00:00 app[web.1]: ]
    2021-01-03T16:03:35.301856+00:00 app[web.1]: }
    2021-01-03T16:03:35.394395+00:00 heroku[web.1]: Process exited with status 1
    2021-01-03T16:03:35.475189+00:00 heroku[web.1]: State changed from starting to crashed
    2021-01-03T16:03:35.479175+00:00 heroku[web.1]: State changed from crashed to starting
    2021-01-03T16:03:39.720428+00:00 heroku[web.1]: Starting process with command `node main.js`

【问题讨论】:

    标签: node.js express heroku deployment


    【解决方案1】:

    您是否正确导出了 './stringToParts' 中的数据?

    当您需要像“./stringToParts”这样的模块时,必须将其导出。 检查您的“./stringToParts”文件末尾是否有类似的内容:

    module.exports = function;

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 2019-01-13
      • 1970-01-01
      • 2016-12-14
      相关资源
      最近更新 更多