Heroku Deploy error: cannot find module '/app/index.js'

I try to deploy the mt application on Heroku, but 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 already added a Procfile file containing the following code: web: node index.js , but I still have the same problem.

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

+7
source share
2 answers
  1. index.js your index.js file in the root directory?

web: node./index.js

  1. Your file can be attached as app/src/index.js

    Web: site. /src/index.js

  2. index.js your index.js have an uppercase index.js "I"? It should be index.js

If you have your index.js file in the root directory of your project, but a Heroku error indicates that the module cannot be found. Then your problem may be related to GIT .

How can we make sure this is so? Well, your git repository might not add the index.js file to commits and put it in heroku. You can verify this by viewing the files that git is viewing in your local repository with the following command:

 git ls-files 

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

Solution : force add your file.

 git add --force ./index.js 

Now you can commit and push to the hero, and you must be in working condition.

This can also happen when your index file is in the dist or src directory (app / dist / index.js or app / src / index.js).

+4
source

Add the relative path for the index.js file below:

 web: node ./index.js 
+3
source

All Articles