【问题标题】:Error in deploying the app in heroku while using the express in the backend在后端使用 express 时在 heroku 中部署应用程序时出错
【发布时间】:2020-01-05 05:13:11
【问题描述】:

每当我尝试在 Heroku 中部署我的后端时,它都会向我显示 express 模块未找到的错误,即使我在 JSON 中正确提及并且此后端在我的本地计算机上运行良好,我试图找到答案但没发现 有关信息,我附上了从 heroku 收到的日志

2020-01-03T10:56:44.902383+00:00 heroku[web.1]: Starting process with command `npm start`
2020-01-03T10:56:47.393235+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-03T10:56:47.356183+00:00 heroku[web.1]: Process exited with status 1
2020-01-03T10:56:47.197595+00:00 app[web.1]: 
2020-01-03T10:56:47.197645+00:00 app[web.1]: > smart-brain-api@1.0.0 start /app
2020-01-03T10:56:47.197655+00:00 app[web.1]: > node server.js
2020-01-03T10:56:47.197657+00:00 app[web.1]: 
2020-01-03T10:56:47.293581+00:00 app[web.1]: internal/modules/cjs/loader.js:800
2020-01-03T10:56:47.293586+00:00 app[web.1]: throw err;
2020-01-03T10:56:47.293588+00:00 app[web.1]: ^
2020-01-03T10:56:47.293590+00:00 app[web.1]: 
2020-01-03T10:56:47.293595+00:00 app[web.1]: Error: Cannot find module 'express'
2020-01-03T10:56:47.293597+00:00 app[web.1]: Require stack:
2020-01-03T10:56:47.293599+00:00 app[web.1]: - /app/server.js
2020-01-03T10:56:47.293623+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2020-01-03T10:56:47.293626+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:690:27)
2020-01-03T10:56:47.293633+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2020-01-03T10:56:47.293635+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-01-03T10:56:47.293637+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:1:15)
2020-01-03T10:56:47.293639+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2020-01-03T10:56:47.293641+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2020-01-03T10:56:47.293643+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2020-01-03T10:56:47.293644+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2020-01-03T10:56:47.293646+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) {
2020-01-03T10:56:47.293648+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-01-03T10:56:47.293650+00:00 app[web.1]: requireStack: [ '/app/server.js' ]
2020-01-03T10:56:47.293652+00:00 app[web.1]: }
2020-01-03T10:56:47.298875+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-03T10:56:47.299147+00:00 app[web.1]: npm ERR! errno 1
2020-01-03T10:56:47.300153+00:00 app[web.1]: npm ERR! smart-brain-api@1.0.0 start: `node server.js`
2020-01-03T10:56:47.300313+00:00 app[web.1]: npm ERR! Exit status 1
2020-01-03T10:56:47.300484+00:00 app[web.1]: npm ERR!
2020-01-03T10:56:47.300625+00:00 app[web.1]: npm ERR! Failed at the smart-brain-api@1.0.0 start script.
2020-01-03T10:56:47.300757+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-01-03T10:56:47.308098+00:00 app[web.1]: 
2020-01-03T10:56:47.308217+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-01-03T10:56:47.308312+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-01-03T10_56_47_301Z-debug.log

【问题讨论】:

  • 你在 package.json 中添加了 express 吗?好像npm没有安装。
  • 我确实在我的 package.json 中添加了快递

标签: node.js heroku npm


【解决方案1】:

你跑之前有npm install吗?乍一看,它表明它找不到节点模块。检查是否已创建 node_modules 文件夹。然后重启服务器。

【讨论】:

  • 我听说它在 heroku 服务器中安装了模块自动模块,当我从文档中阅读时,我删除了所有节点模块并保留了 package.json 文件
  • 没有。查找 node_modules 文件夹。如果它不存在或为空,请执行 npm install。也许某些模块丢失或根本没有安装任何模块。 devcenter.heroku.com/articles/deploying-nodejs 使用本指南
  • 我尝试了文档中给出的所有方法,当我使用命令 heroku local web 运行应用程序时,它运行良好,但每当我在 heroku 上运行相同的方法时,它都会给我同样的错误
【解决方案2】:

我解决了我在使用 express 时遇到的主要问题,因为在 package.json 文件中我在 devDependencies 中提到了它,而不是将其放入依赖项文件中,并且在将 express 放入依赖项对象之后它运行良好。

p>

【讨论】:

    猜你喜欢
    • 2013-07-04
    • 2015-10-09
    • 2021-04-28
    • 2012-02-20
    • 2017-09-20
    • 2020-03-13
    • 1970-01-01
    • 2019-06-18
    • 2018-02-09
    相关资源
    最近更新 更多