'I keep getting this error: Cannot find module '/app/index.js' when deploying to Heroku. How do I fix this?
Few weeks ago when I was deploying my back-end to Heroku, I didn't get any errors. Now I'm doing the exact same thing, and I keep getting this error. The only difference is that I used express before, whereas now I am using express-generator, and the file structure is a bit different.
Now, I have routes folder, and my index.js was inside along with other routes.
I have a Procfile, and inside I have this line web: node index.js. Later I tried with this:
web: node ./index.js but it made no difference.
I also have a .gitignore file, and inside I have this: /node_modules.
My project folder contains two folders - client and server. I am only trying to deploy the server folder. Inside the server, I have 4 folders: bin, node_modules, public and routes, and 6 files - .gitignore, app.js, index.js, Procfile, and the two package files. As I said, index.js was originally inside the routes folder, but I moved it outside to see if it would work, but it's not working.
Inside my package.json file, I have my dependencies - express, cors etc. and my 'scripts' has just one start with the value of node ./index.js but it was originally node ./bin/www this one.
Inside my app.js, I am requiring the index file like this:
const indexRouter = require('./index');
Can anybody please help me figure out what's happening here? Literally 2 weeks ago I deployed an express server and had no issues, and few months ago, I deployed almost identical project to the one I'm doing now, again made with express-generator, and I had no problems. Why am I having errors now?
The heroku logs says the build was successful, but then it throws an error:
Error: Cannot find module '/app/index.js'
I saw that a lot of people have been having this same issue, but their solutions didn't work for me, and their cases seemed a bit different.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
