16

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!

5
  • How do you start your app?like node index.js? Commented Aug 18, 2016 at 12:32
  • I edited a Procfile file and I specified the rule I wrote in my post. Then I start the app by command line launch heroku restart or just in the commit phase directly. Anyway i think the command executed is node index.js Commented Aug 18, 2016 at 12:37
  • generally if you start your app locally as node index.js or node server/index.js same way you should set in Procfile Commented Aug 18, 2016 at 12:45
  • I got the exact same error. Dumb, but I did a F***** Stupid typo in file name... Commented May 10, 2017 at 12:32
  • I too have the same issue! Anybody knows how? I have /app/app.js error. Commented Jul 23, 2020 at 10:49

7 Answers 7

16
  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).

Sign up to request clarification or add additional context in comments.

4 Comments

fatal: pathspec './index.js' did not match any files
Thanks @MauricilLeal! after doing "git ls-files" I noticed my index.js was uploaded as proper case "Index.js", changing the file name locally and pushing to git did not help so i did. "git rm Index.js", then recreated the file in lower case, pushed file up again, and it works!
@JGallardo Did you check that you have an index.js on that path? The file needs to be there and also like Chaim Klar mentioned it has to be lower case (index.js).
Thanks, it helped me. I had folder containing index.js in .gitignore at one point. After I run git add --force dist containing my index.js, heroku executed "start": "node dist/index.js" with no problems.
3

Add relative path for index.js file as bellow

web: node ./index.js

3 Comments

I did it but it doesn't work. I still get the same error.
Are the Procfile and index.js at same path(root)?
Yes, both at the same path.
1

I am getting this error also. then I solve it by fixing importing file. My folder was was in lowercase like the product, and I import it like Product. It doesn't give me errors in localhost. Please check if the import files path is right in the index file.

1 Comment

lowercase filename was causing the issue for me too. Thank You
0

My issue was a fault with my local development environment. Somehow...JavaScript code was being injected into my app project, which I didn't do.

Not knowing this was occurring, Heroku started seeing errors during my push, like "can't find jQuery, even though your using it in your app". I was like "what????, I'm not even using jQuery." I then re-opened a .js file in my project...and there it was, a const variable declaring jquery. So I say all that say, check your VSCode extensions, your third party npm packages, and everything for that matter to make sure things like this are not happening to you.

Comments

0

If error still happening, try using this:

web: node .

Comments

0

Go to your package.json file in root directory of any sub directory with another instance.

Change the script tag from "start": "node start" to "start": "node app.js".

Please note: in my case my main file is app.js yours can be index.js or server.js or anything you named it.

1 Comment

yes exactly, sometimes when we push index.js, it gets changes to app.js, so we have to update package.json and replace index.js to app.js (ex : "start" : "node index.js" =>"start" : "node app.js" ). To be clear , I have pushed index.js on heroku, but when cloned it, I have got app.js in place of index.js. So those are still getting error can try this.
0

it can also happen if you give space in folders name or create your files in multiple folders then it will work in localhost but in server it will give you application error so don't make multiple folders and as well as don't give space in them and specify path correctly then it will work fine.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.