Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku Deploy Error: Cannot find module '/app/index.js'

Tags:

node.js

heroku

I' m trying to deploy mt app on Heroku but I always get the same error:

2016-08-18T10:16:10.988982+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-08-18T10:16:13.180369+00:00 app[web.1]: module.js:341
2016-08-18T10:16:13.180389+00:00 app[web.1]:     throw err;
2016-08-18T10:16:13.180390+00:00 app[web.1]:     ^
2016-08-18T10:16:13.180391+00:00 app[web.1]: 
2016-08-18T10:16:13.180392+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2016-08-18T10:16:13.180393+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:339:15)
2016-08-18T10:16:13.180394+00:00 app[web.1]:     at Function.Module._load (module.js:290:25)
2016-08-18T10:16:13.180394+00:00 app[web.1]:     at Function.Module.runMain (module.js:447:10)
2016-08-18T10:16:13.180399+00:00 app[web.1]:     at node.js:405:3
2016-08-18T10:16:13.271966+00:00 heroku[web.1]: Process exited with status 1
2016-08-18T10:16:13.273383+00:00 heroku[web.1]: State changed from starting to crashed

As I read in similar requests I have already added a Procfile containing the following code: web: node index.js, but I still have same issue.

Anybody have any idea where the problem is? Any guidance would be greatly appreciated. Thank you in advance!

like image 684
trauma Avatar asked Aug 18 '16 10:08

trauma


2 Answers

  1. Is your index.js file in your root directory?
    web: node ./index.js
  1. Your file might be nested like so app/src/index.js
    web: node ./src/index.js
  1. Does your index.js have an uppercase 'I'? It has to be index.js and not Index.js

If you do have your index.js file at the root of your project, but heroku's error says that the module cannot be found. Then, the problem you are having might be due to GIT.

How can we make sure this is the case? Well, your git repo might not be adding your index.js file to commits nor pushing it to heroku. You can verify this by looking at the files that git is watching in your local repo with the following command:

git ls-files

Your index.js file should be listed. If not, then your file is being ignored.

Solution: Force add your file.

git add --force ./index.js

Now you can commit and push to heroku and you should be up and running.

This might also be the case when having your index file inside a dist directory or src (app/dist/index.js or app/src/index.js).

like image 181
MauricioLeal Avatar answered Oct 14 '22 13:10

MauricioLeal


Add relative path for index.js file as bellow

web: node ./index.js
like image 39
Mizanur Rahman Mojumder Avatar answered Oct 14 '22 13:10

Mizanur Rahman Mojumder