在Heroku dyno上运行时,节点应用无法找到模块

时间:2018-02-19 21:28:48

标签: node.js heroku npm

我有一个node.js应用程序,一个API,与heroku local一起使用,但不能在远程dyno上运行。具体来说,它在构建后失败并显示以下消息:

2018-02-19T21:19:38.000000+00:00 app[api]: Build started by user ---
2018-02-19T21:20:01.874321+00:00 heroku[web.1]: State changed from crashed to starting
2018-02-19T21:20:01.588534+00:00 app[api]: Release v16 created by user ---
2018-02-19T21:20:01.588534+00:00 app[api]: Deploy c3f854a0 by user ---
2018-02-19T21:19:38.000000+00:00 app[api]: Build succeeded
2018-02-19T21:20:03.954335+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-19T21:20:05.841898+00:00 app[web.1]: [heroku-exec] Starting
2018-02-19T21:20:06.353423+00:00 app[web.1]: 
2018-02-19T21:20:06.353446+00:00 app[web.1]: > saasaato-backend@1.0.5 start /app
2018-02-19T21:20:06.353449+00:00 app[web.1]: > node dist/server.js
2018-02-19T21:20:06.353451+00:00 app[web.1]: 
2018-02-19T21:20:06.443156+00:00 app[web.1]: module.js:544
2018-02-19T21:20:06.443160+00:00 app[web.1]:     throw err;
2018-02-19T21:20:06.443161+00:00 app[web.1]:     ^
2018-02-19T21:20:06.443163+00:00 app[web.1]: 
2018-02-19T21:20:06.443165+00:00 app[web.1]: Error: Cannot find module '/app/dist/server.js'
2018-02-19T21:20:06.443169+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:542:15)
2018-02-19T21:20:06.443171+00:00 app[web.1]:     at Function.Module._load (module.js:472:25)
2018-02-19T21:20:06.443173+00:00 app[web.1]:     at Function.Module.runMain (module.js:682:10)
2018-02-19T21:20:06.443175+00:00 app[web.1]:     at startup (bootstrap_node.js:191:16)
2018-02-19T21:20:06.443177+00:00 app[web.1]:     at bootstrap_node.js:613:3
2018-02-19T21:20:06.448738+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-02-19T21:20:06.449100+00:00 app[web.1]: npm ERR! errno 1
2018-02-19T21:20:06.450147+00:00 app[web.1]: npm ERR! saasaato-backend@1.0.5 start: `node dist/server.js`
2018-02-19T21:20:06.450299+00:00 app[web.1]: npm ERR! Exit status 1
2018-02-19T21:20:06.450518+00:00 app[web.1]: npm ERR! 
2018-02-19T21:20:06.450686+00:00 app[web.1]: npm ERR! Failed at the saasaato-backend@1.0.5 start script.
2018-02-19T21:20:06.450842+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-02-19T21:20:06.458437+00:00 app[web.1]: 
2018-02-19T21:20:06.458601+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-02-19T21:20:06.458706+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-02-19T21_20_06_451Z-debug.log
2018-02-19T21:20:06.518039+00:00 heroku[web.1]: Process exited with status 1
2018-02-19T21:20:06.535280+00:00 heroku[web.1]: State changed from starting to crashed

此应用程序的先前heroku发布有效,但我无法弄清楚出了什么问题。我试过设置heroku不缓存任何文件,双重检查节点& npm版本等。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您的应用程序脚本如下:

"scripts": { 
   "start": "node dist/server.js" 
}

根据你的启动命令,我可以说你的主文件server.js存在于dist文件夹中,并且必须和应该启动你的应用程序。

由于您在.gitignore中添加了文件夹和服务器文件未被推送到heroku,因此您收到此错误。这是主要原因。

.gitignore主要用于避免将node_modules,unit_test报告和覆盖率以及日志文件等文件推送到您的git存储库。你不应该添加导致此问题的主文件到现在为止。有关.gitignore文件

的更多信息,请参阅此处