internal/modules/cjs/loader.js Heroku - node.js

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.

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.

Heroku Error: Cannot find module './common'

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.

getting error while deploying express app on heroku Error: Cannot find module 'cookie-Parser'

**This is my first deployment and getting an error please help me .as you see in the picture cookie-parser is already listed in the package.josn but it is not installing as dependencies on Heroku and getting errors Cannot find module 'cookie-Parser' and the thing which I noticed in Heroku is P is capital in parser "cookie-Parser" which is a little bit different from the official module spelling. this is my package.json file where cookie parser is listed and I tried both without using and with using #types/cookie-parser but nothing works.
{
"name": "medicare",
"version": "1.0.0",
"description": "Medical solution right at home",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"medical"
],
"author": "Aman",
"license": "ISC",
"dependencies": {
"#types/cookie-parser": "^1.4.2",
"chart.js": "^3.7.0",
"connect-flash": "^0.1.1",
"connect-mongo": "^3.2.0",
"cookie-parser": "^1.4.6",
"cron": "^1.8.2",
"crypto": "^1.0.1",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.2",
"express-ejs-layouts": "^2.5.1",
"express-session": "^1.17.2",
"ical-generator": "^3.1.1",
"joi": "^17.5.0",
"moment": "^2.29.1",
"mongoose": "^6.0.12",
"multer": "^1.4.4",
"node-geocoder": "^3.28.0",
"nodemailer": "^6.7.2",
"passport": "^0.5.0",
"passport-google-oauth": "^2.0.0",
"passport-local": "^1.0.0",
"paytmchecksum": "^1.5.0",
"peer": "^0.6.1",
"socket.io": "^4.4.0"
}
}
and this is the error that I am getting and it is successfully build on Heroku but getting errors while running the app.
2022-01-18T05:32:19.185909+00:00 heroku[web.1]: State changed from crashed to starting
2022-01-18T05:32:22.111839+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-18T05:32:23.773056+00:00 app[web.1]:
2022-01-18T05:32:23.773071+00:00 app[web.1]: > medicare#1.0.0 start /app
2022-01-18T05:32:23.773072+00:00 app[web.1]: > node index.js
2022-01-18T05:32:23.773072+00:00 app[web.1]:
2022-01-18T05:32:24.700130+00:00 app[web.1]: Router is loaded.
2022-01-18T05:32:24.709241+00:00 app[web.1]: internal/modules/cjs/loader.js:905
2022-01-18T05:32:24.709243+00:00 app[web.1]: throw err;
2022-01-18T05:32:24.709244+00:00 app[web.1]: ^
2022-01-18T05:32:24.709244+00:00 app[web.1]:
2022-01-18T05:32:24.709244+00:00 app[web.1]: Error: Cannot find module 'cookie-Parser'
2022-01-18T05:32:24.709245+00:00 app[web.1]: Require stack:
2022-01-18T05:32:24.709245+00:00 app[web.1]: - /app/controllers/users_controller.js
2022-01-18T05:32:24.709246+00:00 app[web.1]: - /app/routes/users.js
2022-01-18T05:32:24.709246+00:00 app[web.1]: - /app/routes/index.js
2022-01-18T05:32:24.709246+00:00 app[web.1]: - /app/index.js
2022-01-18T05:32:24.709247+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2022-01-18T05:32:24.709247+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2022-01-18T05:32:24.709248+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2022-01-18T05:32:24.709248+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2022-01-18T05:32:24.709249+00:00 app[web.1]: at Object.<anonymous> (/app/controllers/users_controller.js:3:20)
2022-01-18T05:32:24.709249+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2022-01-18T05:32:24.709249+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2022-01-18T05:32:24.709249+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2022-01-18T05:32:24.709250+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2022-01-18T05:32:24.709250+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19) {
2022-01-18T05:32:24.709250+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-01-18T05:32:24.709250+00:00 app[web.1]: requireStack: [
2022-01-18T05:32:24.709251+00:00 app[web.1]: '/app/controllers/users_controller.js',2022-01-18T05:32:24.709251+00:00 app[web.1]: '/app/routes/users.js',
2022-01-18T05:32:24.709251+00:00 app[web.1]: '/app/routes/index.js',
2022-01-18T05:32:24.709251+00:00 app[web.1]: '/app/index.js'
2022-01-18T05:32:24.709252+00:00 app[web.1]: ]
2022-01-18T05:32:24.709252+00:00 app[web.1]: }
2022-01-18T05:32:24.721580+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-01-18T05:32:24.721787+00:00 app[web.1]: npm ERR! errno 1
2022-01-18T05:32:24.726938+00:00 app[web.1]: npm ERR! medicare#1.0.0 start: `node index.js`
2022-01-18T05:32:24.727001+00:00 app[web.1]: npm ERR! Exit status 1
2022-01-18T05:32:24.727073+00:00 app[web.1]: npm ERR!
2022-01-18T05:32:24.727122+00:00 app[web.1]: npm ERR! Failed at the medicare#1.0.0 start script.
2022-01-18T05:32:24.727169+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-01-18T05:32:24.732468+00:00 app[web.1]:
2022-01-18T05:32:24.732543+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-01-18T05:32:24.732575+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2022-01-18T05_32_24_727Z-debug.log
2022-01-18T05:32:24.866783+00:00 heroku[web.1]: Process exited with status 1
2022-01-18T05:32:24.969112+00:00 heroku[web.1]: State changed from starting to crashed
2022-01-18T05:32:51.119702+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=medicare-solution.herokuapp.com request_id=45a34311-4c81-48a2-b1f1-d35c4bacbc6d fwd="47.15.123.35" dyno= connect= service= status=503 bytes= protocol=https
2022-01-18T05:32:52.627349+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=medicare-solution.herokuapp.com request_id=3c1c5d1f-1826-4233-a4e2-8a7473d565a0 fwd="47.15.123.35" dyno= connect= service= status=503 bytes= protocol=https

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.

My React/Node application works locally but doesn't work on Heroku

First of all, before downvoting me again please take in mind that before coming here for help I spent all Saturday on this problem and had to take Xanax to get to sleep last night because I was so stressed.
Here is the popular Medium article that I broadly followed
Here is my github repo
Here is the heroku link
I'm pretty sure the problem is related to the package.json files
package.json
{
"name": "example-create-react-app-express",
"version": "1.0.0",
"scripts": {
"client": "cd client && yarn start",
"server": "nodemon --experimental-modules server.mjs",
"dev": "concurrently --kill-others-on-fail \"npm run server --experimental-modules \" \"npm run client --experimental-modules\"",
"start": "npm server.mjs --experimental-modules",
"heroku-postbuild": "cd client && npm install --experimental-modules && npm install --experimental-modules --only=dev --no-shrinkwrap && npm run build --experimental-modules"
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"express": "^4.16.3",
"lorem-ipsum": "^1.0.6",
"mongoose": "^5.2.10",
"shortid": "^2.2.13",
"uuid": "^3.3.2"
},
"devDependencies": {
"concurrently": "^3.5.0",
"dotenv": "^6.0.0"
},
"main": "index.js",
"repository": "git#github.com:HenryPTS/keirei.git",
"author": "HenryPTS <steinbergvhenry#gmail.com>",
"license": "MIT"
}
client/package.json
{
"name": "keirei",
"version": "0.1.0",
"private": true,
"dependencies": {
"autoprefixer": "7.1.6",
"babel-core": "6.26.0",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
"babel-preset-react-app": "^3.1.2",
"babel-runtime": "6.26.0",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
"css-loader": "0.28.7",
"dotenv": "4.0.0",
"dotenv-expand": "4.2.0",
"eslint": "4.10.0",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "1.9.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jsx-a11y": "5.1.1",
"eslint-plugin-react": "7.4.0",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.5",
"fs-extra": "3.0.1",
"html-webpack-plugin": "2.29.0",
"jest": "20.0.4",
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.8",
"promise": "8.0.1",
"raf": "3.4.0",
"react": "^16.4.2",
"react-dev-utils": "^5.0.2",
"react-dom": "^16.4.2",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"resolve": "1.6.0",
"style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
"url-loader": "0.6.2",
"webpack": "3.8.1",
"webpack-dev-server": "2.11.3",
"webpack-manifest-plugin": "1.3.2",
"whatwg-fetch": "2.0.3"
},
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js --env=jsdom"
},
"proxy": "http://localhost:5000/",
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,mjs}"
],
"setupFiles": [
"<rootDir>/config/polyfills.js"
],
"testMatch": [
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"moduleFileExtensions": [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"mjs"
]
},
"babel": {
"presets": [
"react-app"
]
},
"eslintConfig": {
"extends": "react-app"
}
}
Output of heroku logs --tails
2018-10-13T22:19:34.355903+00:00 app[web.1]: npm ERR! example-create-react-app-express#1.0.0 start: `npm server.mjs --experimental-modules`
2018-10-13T22:19:34.355906+00:00 app[web.1]: npm ERR! Exit status 1
2018-10-13T22:19:34.355908+00:00 app[web.1]: npm ERR!
2018-10-13T22:19:34.355911+00:00 app[web.1]: npm ERR! Failed at the example-create-react-app-express#1.0.0 start script.
2018-10-13T22:19:34.355913+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-13T22:19:34.384903+00:00 app[web.1]:
2018-10-13T22:19:34.384911+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-10-13T22_19_34_357Z-debug.log
2018-10-13T22:19:34.384909+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-14T03:55:54.538494+00:00 heroku[web.1]: State changed from crashed to starting
2018-10-14T03:56:03.922469+00:00 heroku[web.1]: Starting process with command `npm start`
2018-10-14T03:56:07.134337+00:00 app[web.1]: > npm server.mjs --experimental-modules
2018-10-14T03:56:07.134338+00:00 app[web.1]:
2018-10-14T03:56:07.134335+00:00 app[web.1]: > example-create-react-app-express#1.0.0 start /app
2018-10-14T03:56:07.134317+00:00 app[web.1]:
2018-10-14T03:56:07.660715+00:00 heroku[web.1]: Process exited with status 1
2018-10-14T03:56:07.677072+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-14T03:56:07.531845+00:00 app[web.1]:
2018-10-14T03:56:07.531864+00:00 app[web.1]: Usage: npm <command>
2018-10-14T03:56:07.531865+00:00 app[web.1]:
2018-10-14T03:56:07.531867+00:00 app[web.1]: where <command> is one of:
2018-10-14T03:56:07.531873+00:00 app[web.1]: completion, config, create, ddp, dedupe, deprecate,
2018-10-14T03:56:07.531879+00:00 app[web.1]: help-search, hook, i, init, install, install-test, it, link,
2018-10-14T03:56:07.531880+00:00 app[web.1]: list, ln, login, logout, ls, outdated, owner, pack, ping,
2018-10-14T03:56:07.531881+00:00 app[web.1]: prefix, profile, prune, publish, rb, rebuild, repo, restart,
2018-10-14T03:56:07.531872+00:00 app[web.1]: access, adduser, audit, bin, bugs, c, cache, ci, cit,
2018-10-14T03:56:07.531883+00:00 app[web.1]: root, run, run-script, s, se, search, set, shrinkwrap, star,
2018-10-14T03:56:07.531874+00:00 app[web.1]: dist-tag, docs, doctor, edit, explore, get, help,
2018-10-14T03:56:07.531884+00:00 app[web.1]: stars, start, stop, t, team, test, token, tst, un,
2018-10-14T03:56:07.531885+00:00 app[web.1]: uninstall, unpublish, unstar, up, update, v, version, view,
2018-10-14T03:56:07.531886+00:00 app[web.1]: whoami
2018-10-14T03:56:07.531892+00:00 app[web.1]: npm <command> -h quick help on <command>
2018-10-14T03:56:07.531895+00:00 app[web.1]: npm help <term> search for help on <term>
2018-10-14T03:56:07.531896+00:00 app[web.1]: npm help npm involved overview
2018-10-14T03:56:07.531887+00:00 app[web.1]:
2018-10-14T03:56:07.531897+00:00 app[web.1]:
2018-10-14T03:56:07.531898+00:00 app[web.1]: Specify configs in the ini-formatted file:
2018-10-14T03:56:07.531893+00:00 app[web.1]: npm -l display full usage info
2018-10-14T03:56:07.531899+00:00 app[web.1]: /app/.npmrc
2018-10-14T03:56:07.531900+00:00 app[web.1]: or on the command line via: npm <command> --key value
2018-10-14T03:56:07.531904+00:00 app[web.1]: npm#6.4.1 /app/.heroku/node/lib/node_modules/npm
2018-10-14T03:56:07.531902+00:00 app[web.1]: Config info can be viewed via: npm help config
2018-10-14T03:56:07.557221+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-14T03:56:07.557696+00:00 app[web.1]: npm ERR! errno 1
2018-10-14T03:56:07.559431+00:00 app[web.1]: npm ERR! example-create-react-app-express#1.0.0 start: `npm server.mjs --experimental-modules`
2018-10-14T03:56:07.559639+00:00 app[web.1]: npm ERR! Exit status 1
2018-10-14T03:56:07.531903+00:00 app[web.1]:
2018-10-14T03:56:07.559927+00:00 app[web.1]: npm ERR!
2018-10-14T03:56:07.538679+00:00 app[web.1]:
2018-10-14T03:56:07.560174+00:00 app[web.1]: npm ERR! Failed at the example-create-react-app-express#1.0.0 start script.
2018-10-14T03:56:07.560363+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-14T03:56:07.584098+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-14T03:56:07.576127+00:00 app[web.1]:
2018-10-14T03:56:07.584103+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-10-14T03_56_07_562Z-debug.log
2018-10-14T09:40:27.916447+00:00 heroku[web.1]: State changed from crashed to starting
2018-10-14T09:40:37.545339+00:00 heroku[web.1]: Starting process with command `npm start`
2018-10-14T09:40:40.686480+00:00 app[web.1]:
2018-10-14T09:40:40.686507+00:00 app[web.1]:
2018-10-14T09:40:40.686504+00:00 app[web.1]: > example-create-react-app-express#1.0.0 start /app
2018-10-14T09:40:40.686506+00:00 app[web.1]: > npm server.mjs --experimental-modules
2018-10-14T09:40:41.864389+00:00 heroku[web.1]: Process exited with status 1
2018-10-14T09:40:41.922343+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-14T09:40:41.681977+00:00 app[web.1]:
2018-10-14T09:40:41.682010+00:00 app[web.1]: Usage: npm <command>
2018-10-14T09:40:41.682011+00:00 app[web.1]:
2018-10-14T09:40:41.682013+00:00 app[web.1]: where <command> is one of:
2018-10-14T09:40:41.682014+00:00 app[web.1]: access, adduser, audit, bin, bugs, c, cache, ci, cit,
2018-10-14T09:40:41.682016+00:00 app[web.1]: completion, config, create, ddp, dedupe, deprecate,
2018-10-14T09:40:41.682017+00:00 app[web.1]: dist-tag, docs, doctor, edit, explore, get, help,
2018-10-14T09:40:41.682020+00:00 app[web.1]: list, ln, login, logout, ls, outdated, owner, pack, ping,
2018-10-14T09:40:41.682019+00:00 app[web.1]: help-search, hook, i, init, install, install-test, it, link,
2018-10-14T09:40:41.682021+00:00 app[web.1]: prefix, profile, prune, publish, rb, rebuild, repo, restart,
2018-10-14T09:40:41.682024+00:00 app[web.1]: stars, start, stop, t, team, test, token, tst, un,
2018-10-14T09:40:41.682023+00:00 app[web.1]: root, run, run-script, s, se, search, set, shrinkwrap, star,
2018-10-14T09:40:41.682025+00:00 app[web.1]: uninstall, unpublish, unstar, up, update, v, version, view,
2018-10-14T09:40:41.682043+00:00 app[web.1]: whoami
2018-10-14T09:40:41.682044+00:00 app[web.1]:
2018-10-14T09:40:41.682046+00:00 app[web.1]: npm <command> -h quick help on <command>
2018-10-14T09:40:41.682047+00:00 app[web.1]: npm -l display full usage info
2018-10-14T09:40:41.682049+00:00 app[web.1]: npm help <term> search for help on <term>
2018-10-14T09:40:41.682050+00:00 app[web.1]: npm help npm involved overview
2018-10-14T09:40:41.682051+00:00 app[web.1]:
2018-10-14T09:40:41.682053+00:00 app[web.1]: Specify configs in the ini-formatted file:
2018-10-14T09:40:41.682054+00:00 app[web.1]: /app/.npmrc
2018-10-14T09:40:41.682055+00:00 app[web.1]: or on the command line via: npm <command> --key value
2018-10-14T09:40:41.682057+00:00 app[web.1]: Config info can be viewed via: npm help config
2018-10-14T09:40:41.682058+00:00 app[web.1]:
2018-10-14T09:40:41.682059+00:00 app[web.1]: npm#6.4.1 /app/.heroku/node/lib/node_modules/npm
2018-10-14T09:40:41.696647+00:00 app[web.1]:
2018-10-14T09:40:41.726240+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-14T09:40:41.726891+00:00 app[web.1]: npm ERR! errno 1
2018-10-14T09:40:41.729370+00:00 app[web.1]: npm ERR! example-create-react-app-express#1.0.0 start: `npm server.mjs --experimental-modules`
2018-10-14T09:40:41.729679+00:00 app[web.1]: npm ERR! Exit status 1
2018-10-14T09:40:41.730068+00:00 app[web.1]: npm ERR!
2018-10-14T09:40:41.730338+00:00 app[web.1]: npm ERR! Failed at the example-create-react-app-express#1.0.0 start script.
2018-10-14T09:40:41.730657+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-14T09:40:41.753088+00:00 app[web.1]:
2018-10-14T09:40:41.753715+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-14T09:40:41.754237+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2018-10-14T09_40_41_733Z-debug.log
2018-10-14T09:45:51.746113+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=keirei.herokuapp.com request_id=77433bae-0184-481d-8c4e-d91ec8ae6618 fwd="86.5.20.156" dyno= connect= service= status=503 bytes= protocol=https
2018-10-14T09:45:53.089110+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=keirei.herokuapp.com request_id=d7039d9e-82c4-4513-bfce-be4e534de0b4 fwd="86.5.20.156" dyno= connect= service= status=503 bytes= protocol=https
The .env variables necessary for connecting to the server are:
DB_URI=mongodb://ds135952.mlab.com:35952/keirei-db
DB_USER=admin
DB_PASS=limit5
Again, before downvoting, please bear in mind that I an new, lacking in intelligence, and made a genuine and concerted effort to fix the problem on my own before coming here.

Resources