Heroku Error: Cannot find module './common' - node.js

I was trying to deploy a practice project to Heroku and it gets deployed. However there is a application error, which is preventing the app to run on the server. I got some details about the errors, after running heroku logs.
2022-03-07T01:25:09.883329+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-03-07T01:25:09.883379+00:00 app[web.1]: throw err;
2022-03-07T01:25:09.883379+00:00 app[web.1]: ^
2022-03-07T01:25:09.883379+00:00 app[web.1]:
2022-03-07T01:25:09.883380+00:00 app[web.1]: Error: Cannot find module './common'
2022-03-07T01:25:09.883380+00:00 app[web.1]: Require stack:
2022-03-07T01:25:09.883380+00:00 app[web.1]: - /app/node_modules/debug/src/node.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/debug/src/index.js
2022-03-07T01:25:09.883381+00:00 app[web.1]: - /app/node_modules/mquery/lib/mquery.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/promise_provider.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
2022-03-07T01:25:09.883382+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
2022-03-07T01:25:09.883383+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/db/connect.js
2022-03-07T01:25:09.883386+00:00 app[web.1]: - /app/app.js
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-07T01:25:09.883387+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-07T01:25:09.883388+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/debug/src/node.js:240:18)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
2022-03-07T01:25:09.883389+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-07T01:25:09.883390+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-07T01:25:09.883390+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-07T01:25:09.883390+00:00 app[web.1]: requireStack: [
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/node.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/debug/src/index.js',
2022-03-07T01:25:09.883391+00:00 app[web.1]: '/app/node_modules/mquery/lib/mquery.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/promise_provider.js',
2022-03-07T01:25:09.883392+00:00 app[web.1]: '/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
2022-03-07T01:25:09.883393+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/db/connect.js',
2022-03-07T01:25:09.883394+00:00 app[web.1]: '/app/app.js'
2022-03-07T01:25:09.883394+00:00 app[web.1]: ]
2022-03-07T01:25:09.883395+00:00 app[web.1]: }
2022-03-07T01:25:10.033008+00:00 heroku[web.1]: Process exited with status 1
2022-03-07T01:25:10.264584+00:00 heroku[web.1]: State changed from starting to crashed
I have installed the common package separately using npm install common --save, but that did not solve the issue. Also deleted node_modules and reinstalled all the modules. However nothing seems to work. I've scoured the internet for an answer to this, and haven't found anything yet that works.
My package.json looks like this,
{
"name": "starter-again",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"dotenv": "^16.0.0",
"nodemon": "^2.0.15"
},
"dependencies": {
"common": "^0.2.5",
"debug": "^4.3.3",
"express": "^4.17.3",
"mongoose": "^6.2.4"
},
"engines": {
"node": "16.14.0"
},
}
Any suggestion on how to solve this error?

I solved this by not having node_modules in my .gitignore folder which was there originally.

Related

missing module when deploy nodejs application to heroku

When I tried to deploy my app to heroku, I kept getting this error in the log
2022-05-20T14:49:35.602605+00:00 app[web.1]: > node server.js
2022-05-20T14:49:35.602605+00:00 app[web.1]:
2022-05-20T14:49:35.719423+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-05-20T14:49:35.719424+00:00 app[web.1]: throw err;
2022-05-20T14:49:35.719425+00:00 app[web.1]: ^
2022-05-20T14:49:35.719428+00:00 app[web.1]:
2022-05-20T14:49:35.719428+00:00 app[web.1]: Error: Cannot find module 'csv-parse'
2022-05-20T14:49:35.719428+00:00 app[web.1]: Require stack:
2022-05-20T14:49:35.719429+00:00 app[web.1]: - /app/server.js
2022-05-20T14:49:35.719430+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-05-20T14:49:35.719431+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-05-20T14:49:35.719431+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-05-20T14:49:35.719431+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-05-20T14:49:35.719432+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:6:15)
2022-05-20T14:49:35.719432+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-20T14:49:35.719432+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-20T15:08:40.259973+00:00 app[web.1]: Error: Cannot find module 'express'
2022-05-20T15:08:40.259974+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:536:15)
2022-05-20T15:08:40.259974+00:00 app[web.1]: at Function.Module._load (module.js:466:25)
2022-05-20T15:08:40.259974+00:00 app[web.1]: at Module.require (module.js:579:17)
2022-05-20T15:08:40.259974+00:00 app[web.1]: at require (internal/module.js:11:18)
2022-05-20T15:08:40.259975+00:00 app[web.1]: at Object.<anonymous> (/app/server.js:5:17)
2022-05-20T15:08:40.259975+00:00 app[web.1]: at Module._compile (module.js:635:30)
2022-05-20T15:08:40.259975+00:00 app[web.1]: at Object.Module._extensions..js (module.js:646:10)
2022-05-20T15:08:40.259975+00:00 app[web.1]: at Module.load (module.js:554:32)
2022-05-20T15:08:40.259976+00:00 app[web.1]: at tryModuleLoad (module.js:497:12)
I am pretty sure the node.js application can successfully run locally and I have installed all the necessary packages in dependencies inside package.json. Not sure how to fix it....
Here is my package.json
{
"name": "Netflix User Study Framework",
"version": "1.0.0",
"description": "Encode username into prolific id",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"engines": {
"node": "8.9.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/amyhua/basic-website-template-node.git"
},
"author": "YOUR NAME GOES HERE",
"bugs": {
"url": "https://github.com/amyhua/basic-website-template-node/issues"
},
"homepage": "https://github.com/amyhua/basic-website-template-node#readme",
"dependencies": {
"aws-sdk": "^2.1139.0",
"csv-parser": "^3.0.0",
"csv-stringify": "^6.0.5",
"express": "^4.14.0",
"generate-unique-id": "^2.0.1",
"http": "0.0.0",
"multer": "^1.4.4",
"nodemon": "^1.11.0",
"os": "^0.1.2"
}
}
Also, I set up a .env file with PORT # on 3000.

Why Heroku don't find moment?

i am creating a discord bot and hosting it on heroku. i installed the moment.js library but it can't find it giving the following error
2022-03-27T12:41:48.954612+00:00 app[worker.1]: Error: Cannot find module 'moment'
2022-03-27T12:41:48.954612+00:00 app[worker.1]: Require stack:
2022-03-27T12:41:48.954612+00:00 app[worker.1]: - /app/bot.js
2022-03-27T12:41:48.954622+00:00 app[worker.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-27T12:41:48.954625+00:00 app[worker.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-27T12:41:48.954625+00:00 app[worker.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-27T12:41:48.954626+00:00 app[worker.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-27T12:41:48.954626+00:00 app[worker.1]: at Object.<anonymous> (/app/bot.js:3:16)
2022-03-27T12:41:48.954626+00:00 app[worker.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-27T12:41:48.954626+00:00 app[worker.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-03-27T12:41:48.954627+00:00 app[worker.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-27T12:41:48.954627+00:00 app[worker.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-27T12:41:48.954627+00:00 app[worker.1]: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
2022-03-27T12:41:48.954628+00:00 app[worker.1]: code: 'MODULE_NOT_FOUND',
2022-03-27T12:41:48.954628+00:00 app[worker.1]: requireStack: [ '/app/bot.js' ]
2022-03-27T12:41:48.954628+00:00 app[worker.1]: }
my code
const moment = require('moment');
how should i do?
package.json:
{
"name": "freaksland-bot",
"version": "1.0.0",
"description": "",
"main": "bot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#discordjs/voice": "^0.8.0",
"moment.js": "^2.29.1",
"discord.js": "^13.6.0",
"init": "^0.1.2"
}
}
You are depending on moment.js, but the correct package is just moment.
Did you manually add that to your package.json? First, remove that line.
Then add the correct package:
If you are using Yarn, run yarn add moment
If you are using NPM, run npm install moment
This should install the dependency locally and also add it to your package.json and the relevant lock file. Commit the changes to those files and redeploy.

internal/modules/cjs/loader.js Heroku

My package.json:
{
"name": "api-auth",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"start-dev": "nodemon ./bin/www",
"build": "npm install --only=dev"
},
"engines": {
"node": "v12.6.0",
"npm": "6.9.0"
},
"dependencies": {
"bcrypt": "^3.0.6",
"body-parser": "~1.18.2",
"connect-mongo": "^2.0.1",
"connect-multiparty": "^2.2.0",
"cookie-parser": "~1.4.3",
"cors": "^2.8.5",
"debug": "~2.6.9",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"mongoose": "^5.3.0",
"morgan": "~1.9.0",
"node-gyp": "^3.8.0",
"serve-favicon": "~2.4.5",
"socket.io": "^2.3.0",
"nodemon": "^1.18.6"
},
"devDependencies": {}
}
Heroku output, it build okay but then it shows this:
2020-11-30T17:32:23.000000+00:00 app[api]: Build succeeded
2020-11-30T17:32:25.385955+00:00 heroku[web.1]: Starting process with command `npm start`
2020-11-30T17:32:27.462352+00:00 app[web.1]:
2020-11-30T17:32:27.462366+00:00 app[web.1]: > api-auth#0.0.0 start /app
2020-11-30T17:32:27.462366+00:00 app[web.1]: > node ./bin/www
2020-11-30T17:32:27.462366+00:00 app[web.1]:
2020-11-30T17:32:27.998108+00:00 app[web.1]: internal/modules/cjs/loader.js:628
2020-11-30T17:32:27.998157+00:00 app[web.1]: throw err;
2020-11-30T17:32:27.998157+00:00 app[web.1]: ^
2020-11-30T17:32:27.998158+00:00 app[web.1]:
2020-11-30T17:32:27.998159+00:00 app[web.1]: Error: Cannot find module '../models/User'
2020-11-30T17:32:27.998160+00:00 app[web.1]: Require stack:
2020-11-30T17:32:27.998161+00:00 app[web.1]: - /app/routes/auth.js
2020-11-30T17:32:27.998161+00:00 app[web.1]: - /app/app.js
2020-11-30T17:32:27.998161+00:00 app[web.1]: - /app/bin/www
2020-11-30T17:32:27.998163+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
2020-11-30T17:32:27.998163+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:527:27)
2020-11-30T17:32:27.998164+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:683:19)
2020-11-30T17:32:27.998165+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:16:16)
2020-11-30T17:32:27.998165+00:00 app[web.1]: at Object.<anonymous> (/app/routes/auth.js:9:14)
2020-11-30T17:32:27.998166+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2020-11-30T17:32:27.998166+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2020-11-30T17:32:27.998167+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:643:32)
2020-11-30T17:32:27.998167+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12)
2020-11-30T17:32:27.998167+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:683:19)
2020-11-30T17:32:27.998168+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:16:16)
2020-11-30T17:32:27.998168+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:14:14)
2020-11-30T17:32:27.998169+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2020-11-30T17:32:27.998169+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2020-11-30T17:32:27.998169+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:643:32)
2020-11-30T17:32:27.998170+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:556:12) {
2020-11-30T17:32:27.998170+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-11-30T17:32:27.998171+00:00 app[web.1]: requireStack: [ '/app/routes/auth.js', '/app/app.js', '/app/bin/www' ]
2020-11-30T17:32:27.998171+00:00 app[web.1]: }
2020-11-30T17:32:28.008736+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-11-30T17:32:28.008952+00:00 app[web.1]: npm ERR! errno 1
2020-11-30T17:32:28.009802+00:00 app[web.1]: npm ERR! api-auth#0.0.0 start: `node ./bin/www`
2020-11-30T17:32:28.009951+00:00 app[web.1]: npm ERR! Exit status 1
2020-11-30T17:32:28.010125+00:00 app[web.1]: npm ERR!
2020-11-30T17:32:28.010259+00:00 app[web.1]: npm ERR! Failed at the api-auth#0.0.0 start script.
2020-11-30T17:32:28.010391+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-11-30T17:32:28.014982+00:00 app[web.1]:
2020-11-30T17:32:28.015107+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-11-30T17:32:28.015194+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-11-30T17_32_28_011Z-debug.log
2020-11-30T17:32:28.065317+00:00 heroku[web.1]: Process exited with status 1
2020-11-30T17:32:28.091892+00:00 heroku[web.1]: State changed from starting to crashed
I read this heroku's official page too https://devcenter.heroku.com/articles/troubleshooting-node-deploys but for me is not working: I read that I have to put all the dependencies inside dependencies, and not in devDependencies, so I did that but nothing happens, the error still there.
I tried to delete node_modules and npm i later and is still making the same mistake.
I read too about using a heroku CLI but didnt work for me. I am using github because is easier for me.
Any help please? Thanks.
It was a Windows's problem. Windows doesnt differenciate between upper and lower case like Linux. So when I tried to upload my code, it breaks. I write everything in lower case and it works.

Heroku Deployment of node js

So I am trying to deploy a discord bot through heroku but am having issues with the deployment.. everything works fine when I run my bot locally but when trying to deploy to heroku I get this:
2020-03-21T18:08:07.914594+00:00 heroku[worker.1]: Starting process with command node index.js
2020-03-21T18:08:08.476878+00:00 heroku[worker.1]: State changed from starting to up
2020-03-21T18:08:10.286392+00:00 heroku[worker.1]: State changed from up to crashed
2020-03-21T18:08:10.215281+00:00 app[worker.1]: internal/modules/cjs/loader.js:796
2020-03-21T18:08:10.215306+00:00 app[worker.1]: throw err;
2020-03-21T18:08:10.215307+00:00 app[worker.1]: ^
2020-03-21T18:08:10.215307+00:00 app[worker.1]:
2020-03-21T18:08:10.215307+00:00 app[worker.1]: Error: Cannot find module 'enmap'
2020-03-21T18:08:10.215308+00:00 app[worker.1]: Require stack:
2020-03-21T18:08:10.215308+00:00 app[worker.1]: - /app/index.js
2020-03-21T18:08:10.215323+00:00 app[worker.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
2020-03-21T18:08:10.215324+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:686:27)
2020-03-21T18:08:10.215329+00:00 app[worker.1]: at Module.require (internal/modules/cjs/loader.js:848:19)
2020-03-21T18:08:10.215330+00:00 app[worker.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-03-21T18:08:10.215330+00:00 app[worker.1]: at Object. (/app/index.js:4:15)
2020-03-21T18:08:10.215330+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:955:30)
2020-03-21T18:08:10.215331+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
2020-03-21T18:08:10.215331+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:811:32)
2020-03-21T18:08:10.215331+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:723:14)
2020-03-21T18:08:10.215331+00:00 app[worker.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10) {
2020-03-21T18:08:10.215337+00:00 app[worker.1]: code: 'MODULE_NOT_FOUND',
2020-03-21T18:08:10.215337+00:00 app[worker.1]: requireStack: [ '/app/index.js' ]
2020-03-21T18:08:10.215337+00:00 app[worker.1]: }
2020-03-21T18:08:10.270170+00:00 heroku[worker.1]: Process exited with status 1
I have followed steps found at https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies. but still getting error.. the app log is saying the app is deployed but the bot is not coming online. I don't know what to do at this point. Any help or point to any article would be greatly helpful.
my package.json is here >
{
"name": "botname",
"version": "1.0.0",
"description": "botname Discord Server Bot",
"main": "index.js",
"start": "node .",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Skemicle",
"license": "ISC",
"dependencies": {
"discord.js": "^11.5.1"
},
"engines": {
"node": "12.14.1",
"npm": "6.13.4"
}
}
"dependencies": {
"discord.js": "^11.5.1",
"enmap": "^5.2.4"
},
you have to add enmap to dependencies and if you are using other npm libraries you have to add that to dependencies also because heroku installs dependencies via npm install and that downloads packages listed in package.json -> dependencies.

Unable to find module cors in heroku

I am running a React/NodeJS project on Heroku. My first time installing a project on Heroku. The deployment ran fine, but then I get the following error:
> ProductInventoryApp#1.0.0 start /app
2020-01-12T04:55:41.635051+00:00 app[web.1]: > node ./backend/app.js
2020-01-12T04:55:41.635053+00:00 app[web.1]:
2020-01-12T04:55:42.404864+00:00 app[web.1]: internal/modules/cjs/loader.js:800
2020-01-12T04:55:42.404909+00:00 app[web.1]: throw err;
2020-01-12T04:55:42.404911+00:00 app[web.1]: ^
2020-01-12T04:55:42.404913+00:00 app[web.1]:
2020-01-12T04:55:42.404916+00:00 app[web.1]: Error: Cannot find module 'CORS'
2020-01-12T04:55:42.404918+00:00 app[web.1]: Require stack:
2020-01-12T04:55:42.404921+00:00 app[web.1]: - /app/backend/app.js
2020-01-12T04:55:42.404923+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
2020-01-12T04:55:42.404925+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:690:27)
2020-01-12T04:55:42.404927+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:852:19)
2020-01-12T04:55:42.404929+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-01-12T04:55:42.404931+00:00 app[web.1]: at Object.<anonymous> (/app/backend/app.js:5:12)
2020-01-12T04:55:42.404933+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:959:30)
2020-01-12T04:55:42.404935+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
2020-01-12T04:55:42.404937+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:815:32)
2020-01-12T04:55:42.404939+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:727:14)
2020-01-12T04:55:42.404941+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
2020-01-12T04:55:42.404943+00:00 app[web.1]: at internal/main/run_main_module.js:17:11 {
2020-01-12T04:55:42.404945+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2020-01-12T04:55:42.404946+00:00 app[web.1]: requireStack: [ '/app/backend/app.js' ]
2020-01-12T04:55:42.404948+00:00 app[web.1]: }
2020-01-12T04:55:42.427634+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-01-12T04:55:42.428331+00:00 app[web.1]: npm ERR! errno 1
2020-01-12T04:55:42.430180+00:00 app[web.1]: npm ERR! ProductInventoryApp#1.0.0 start: `node ./backend/app.js`
2020-01-12T04:55:42.430622+00:00 app[web.1]: npm ERR! Exit status 1
The cors has been included in my dependencies. So not sure where the problem lies.
package.json for nodeJS
{
"name": "ProductInventoryApp",
"version": "1.0.0",
"description": "",
"engines": {
"node": "12.13.1"
},
"main": "./backend/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./backend/app.js",
"client-install": "npm install --prefix client",
"server": "nodemon ./backend/app.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.3.0",
"mongodb": "^3.4.0",
"mongoose": "^5.8.0",
"uuid": "^3.3.3"
},
"devDependencies": {
"concurrently": "^4.0.1",
"cors": "^2.8.5"
}
}
You need move cors package from devDependencies into dependencies. This is because heroku runs your node app in production mode, devDependencies are not installed in production mode.

Resources