Node App在Heroku中崩溃-错误:找不到模块

时间:2018-08-14 15:12:34

标签: node.js heroku

我是Heroku的新手,正在尝试让我的第一个Node应用程序在其中运行。该应用程序是基本的会话身份验证应用程序。它在本地运行良好,但是当我部署到Heroku时,我得到:

2018-08-14T14:52:34.590534+00:00 heroku[web.1]: Starting process with command `node session.js`
2018-08-14T14:52:36.965521+00:00 heroku[web.1]: State changed from starting to crashed
2018-08-14T14:52:36.939947+00:00 heroku[web.1]: Process exited with status 1
2018-08-14T14:52:36.856913+00:00 app[web.1]: module.js:549
2018-08-14T14:52:36.856932+00:00 app[web.1]: throw err;
2018-08-14T14:52:36.856934+00:00 app[web.1]: ^
2018-08-14T14:52:36.856935+00:00 app[web.1]: 
2018-08-14T14:52:36.856937+00:00 app[web.1]: Error: Cannot find module '/app/session.js'
2018-08-14T14:52:36.856939+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:547:15)
2018-08-14T14:52:36.856940+00:00 app[web.1]: at Function.Module._load (module.js:474:25)
2018-08-14T14:52:36.856942+00:00 app[web.1]: at Function.Module.runMain (module.js:693:10)
2018-08-14T14:52:36.856943+00:00 app[web.1]: at startup (bootstrap_node.js:191:16)
2018-08-14T14:52:36.856945+00:00 app[web.1]: at bootstrap_node.js:612:3

我正在本地和Heroku中运行相同版本的Node和npm(尽管我没有在package.json中指定引擎)。 节点:8.11.3 npm:5.6.0

这是我的package.json:

{
  "name": "session",
  "version": "1.0.0",
  "description": "Authentication system for web portal",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "Damian Duffy",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^2.0.1",
    "body-parser": "^1.18.3",
    "cookie-parser": "^1.4.3",
    "express": "^4.16.3",
    "express-session": "^1.15.6",
    "morgan": "^1.9.0",
    "pg": "^7.4.3",
    "sequelize": "^4.37.10"
  }
}

我添加了Procfile来启动“网络:节点session.js”

我的node_modules目录被Git忽略。

我一直在努力使它在Heroku上正常工作,但是我似乎没有任何办法解决此问题。我已经在Heroku上删除了该应用程序,生成了新的package.json,在本地进行了重新测试,重新部署,但似乎无济于事。

2 个答案:

答案 0 :(得分:0)

您可以尝试添加并提交丢失的文件,然后将其推送到heroku并再次检查吗?

答案 1 :(得分:0)

问题出在我为Heroku创建的Procfile中。我已经指示Heroku启动session.js而不是server.js。真是愚蠢的错误,只有在休息一会后才发现它。

我不完全理解添加到session.js拼写错误中的“ / app /”路径。我的节点应用程序中没有这样的路径。我猜Heroku会参考用户的测功机返回一个通用的'/ app /'?