在使用 Express 后端部署应用到 Heroku 时出现错误。

huangapple go评论84阅读模式
英文:

Error in deploying the app in heroku while using the express in the backend

问题

每当我尝试在Heroku部署我的后端时,它都会显示错误,即使我在JSON中正确地提到了express模块,而且这个后端在我的本地计算机上运行得非常好。我尝试找到答案,但没有找到。

关于信息,我附上了我从Heroku收到的日志:

2020-01-03T10:56:44.902383+00:00 heroku[web.1]: 启动进程的命令 `npm start`
2020-01-03T10:56:47.393235+00:00 heroku[web.1]: 状态从启动中变为崩溃
2020-01-03T10:56:47.356183+00:00 heroku[web.1]: 进程以状态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]: 报错;
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]: 错误: 找不到模块 'express'
2020-01-03T10:56:47.293597+00:00 app[web.1]: 需要堆栈:
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]: 在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2020-01-03T10:56:47.293626+00:00 app[web.1]: 在 Function.Module._load (internal/modules/cjs/loader.js:690:27)
2020-01-03T10:56:47.293633+00:00 app[web.1]: 在 Module.require (internal/modules/cjs/loader.js:852:19)
2020-01-03T10:56:47.293635+00:00 app[web.1]: 在 require (internal/modules/cjs/helpers.js:74:18)
2020-01-03T10:56:47.293637+00:00 app[web.1]: 在 Object.<anonymous> (/app/server.js:1:15)
2020-01-03T10:56:47.293639+00:00 app[web.1]: 在 Module._compile (internal/modules/cjs/loader.js:959:30)
2020-01-03T10:56:47.293641+00:00 app[web.1]: 在 Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2020-01-03T10:56:47.293643+00:00 app[web.1]: 在 Module.load (internal/modules/cjs/loader.js:815:32)
2020-01-03T10:56:47.293644+00:00 app[web.1]: 在 Function.Module._load (internal/modules/cjs/loader.js:727:14)
2020-01-03T10:56:47.293646+00:00 app[web.1]: 在 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! 退出状态 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! 在 smart-brain-api@1.0.0 start 脚本失败。
2020-01-03T10:56:47.300757+00:00 app[web.1]: npm ERR! 这可能不是npm的问题。可能有额外的日志输出在上面。
2020-01-03T10:56:47.308098+00:00 app[web.1]: 
2020-01-03T10:56:47.308217+00:00 app[web.1]: npm ERR! 可以在以下位置找到此运行的完整日志:
2020-01-03T10:56:47.308312+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-01-03T10_56_47_301Z-debug.log
英文:

Whenever I am trying to deploy my backend in Heroku it is showing me the error that express module not found even though I properly mentioned in the JSON and this backend was working perfectly fine in my local computer and I tried to find the answer but didn't found out
For the information, I am attaching the log I received from 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

答案1

得分: 2

你在运行之前是否执行了 npm install?从第一眼看,它显示找不到 Node 模块。检查一下是否已创建了 node_modules 文件夹,然后重新启动服务器。

英文:

Did you do npm install before running ? From first look, it shows that it cannot find node modules. Check if the node_modules folder has been created. Then restart the server.

答案2

得分: 0

我解决了我在express中遇到的主要问题,因为在package.json文件中,我将它放在了devDependencies中,而不是放在dependencies文件中,将express放在dependencies对象中后,它就正常工作了。

英文:

I solved my problem the main issue that I was having with express because in the package.json file I mentioned it in the devDependencies instead of putting it in dependencies file and after putting the express in dependencies object it worked well.

huangapple
  • 本文由 发表于 2020年1月3日 19:28:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577824.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定