Error: Cannot find module 'mongoose' in heroku - node.js

When we try to deploy our nodejs app in heroku that show us this problem !
by the way I have large app that content a lot of routes. I are not knew if can deploy it with this way I have litter confuse.
//package.json
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/ww"
},
for runing Heroku : npm start
2021-10-17T19:17:50.244905+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2021-10-17T19:17:50.244906+00:00 app[web.1]: Require stack:
2021-10-17T19:17:50.244906+00:00 app[web.1]: - /app/routes/users.js
2021-10-17T19:17:50.244906+00:00 app[web.1]: - /app/routes/index.js
2021-10-17T19:17:50.244907+00:00 app[web.1]: - /app/app.js
2021-10-17T19:17:50.244907+00:00 app[web.1]: - /app/bin/www
2021-10-17T19:17:50.244907+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
2021-10-17T19:17:50.244908+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:746:27)
2021-10-17T19:17:50.244908+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at Object.<anonymous> (/app/routes/users.js:10:16)
2021-10-17T19:17:50.244909+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-17T19:17:50.244910+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-17T19:17:50.244911+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19) {
2021-10-17T19:17:50.244911+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-10-17T19:17:50.244911+00:00 app[web.1]: requireStack: [
2021-10-17T19:17:50.244911+00:00 app[web.1]: '/app/routes/users.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/routes/index.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/app.js',
2021-10-17T19:17:50.244912+00:00 app[web.1]: '/app/bin/www'
2021-10-17T19:17:50.244913+00:00 app[web.1]: ]
2021-10-17T19:17:50.244913+00:00 app[web.1]: }
2021-10-17T19:17:50.261989+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-17T19:17:50.262348+00:00 app[web.1]: npm ERR! errno 1
2021-10-17T19:17:50.269748+00:00 app[web.1]: npm ERR! project-work#0.0.0 start: `node ./bin/www`
2021-10-17T19:17:50.269860+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-17T19:17:50.269999+00:00 app[web.1]: npm ERR!
2021-10-17T19:17:50.270110+00:00 app[web.1]: npm ERR! Failed at the project-work#0.0.0 start script.
2021-10-17T19:17:50.270230+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-17T19:17:50.274000+00:00 app[web.1]:
2021-10-17T19:17:50.274070+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-17T19:17:50.274112+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-10-17T19_17_50_270Z-debug.log
2021-10-17T19:17:50.422905+00:00 heroku[web.1]: Process exited with status 1
2021-10-17T19:17:50.494116+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-17T19:17:50.498518+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-17T19:17:52.375838+00:00 heroku[web.1]: Starting process with command `

Related

How to get rid of Heroku deploy error "Error: Cannot find module '../models/people' " for Node.js app?

I am trying to deploy a node.js app to heroku. But I am facing this ("Error: Cannot find module '../models/people' ) error. The app is working fine in localhost.
2022-11-01T17:45:47.000000+00:00 app[api]: Build succeeded
2022-11-01T17:45:47.265323+00:00 heroku[web.1]: State changed from crashed to starting
2022-11-01T17:45:50.307944+00:00 heroku[web.1]: Starting process with command `NODE_ENV=production node index.js`
2022-11-01T17:45:52.192313+00:00 app[web.1]: node:internal/modules/cjs/loader:936
2022-11-01T17:45:52.192350+00:00 app[web.1]: throw err;
2022-11-01T17:45:52.192350+00:00 app[web.1]: ^
2022-11-01T17:45:52.192351+00:00 app[web.1]:
2022-11-01T17:45:52.192351+00:00 app[web.1]: Error: Cannot find module '../models/people'
2022-11-01T17:45:52.192351+00:00 app[web.1]: Require stack:
2022-11-01T17:45:52.192351+00:00 app[web.1]: - /app/controller/login_controller.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: - /app/router/login_router.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: - /app/index.js
2022-11-01T17:45:52.192352+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-11-01T17:45:52.192353+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Object.<anonymous> (/app/controller/login_controller.js:2:14)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-11-01T17:45:52.192354+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-11-01T17:45:52.192355+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-11-01T17:45:52.192355+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-11-01T17:45:52.192356+00:00 app[web.1]: requireStack: [
2022-11-01T17:45:52.192356+00:00 app[web.1]: '/app/controller/login_controller.js',
2022-11-01T17:45:52.192356+00:00 app[web.1]: '/app/router/login_router.js',
2022-11-01T17:45:52.192357+00:00 app[web.1]: '/app/index.js'
2022-11-01T17:45:52.192357+00:00 app[web.1]: ]
2022-11-01T17:45:52.192357+00:00 app[web.1]: }
2022-11-01T17:45:52.307078+00:00 heroku[web.1]: Process exited with status 1
2022-11-01T17:45:52.382922+00:00 heroku[web.1]: State changed from starting to crashed

SyntaxError: Unexpected token

I am trying to deploy my code on heroku and it give me Error.
Provide me the solution.
It show unexpected token ... which i cannot resolve.
i am using mongo atlas online database link to connect to database.
For more clearity i am adding my git repository
github.com/laxitnahar/temp
ERROR:-
2022-08-05T11:57:48.831721+00:00 heroku[web.1]: State changed from crashed to starting
2022-08-05T11:57:51.114009+00:00 heroku[web.1]: Starting process with command `npm start`
2022-08-05T11:57:52.585567+00:00 app[web.1]:
2022-08-05T11:57:52.585595+00:00 app[web.1]: > backend#1.0.0 start /app
2022-08-05T11:57:52.585596+00:00 app[web.1]: > node server.js
2022-08-05T11:57:52.585596+00:00 app[web.1]:
2022-08-05T11:57:52.809406+00:00 app[web.1]: /app/node_modules/connect-mongo/build/main/lib/MongoStore.js:75
2022-08-05T11:57:52.809420+00:00 app[web.1]: constructor({ collectionName = 'sessions', ttl = 1209600, mongoOptions = {}, autoRemove = 'native', autoRemoveInterval = 10, touchAfter = 0, stringify = true, crypto, ...required }) {
2022-08-05T11:57:52.809423+00:00 app[web.1]: ^^^
2022-08-05T11:57:52.809423+00:00 app[web.1]: SyntaxError: Unexpected token ...
2022-08-05T11:57:52.809423+00:00 app[web.1]: at createScript (vm.js:56:10)
2022-08-05T11:57:52.809423+00:00 app[web.1]: at Object.runInThisContext (vm.js:97:10)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Module._compile (module.js:542:28)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at Module.load (module.js:487:32)
2022-08-05T11:57:52.809424+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at Module.require (module.js:497:17)
2022-08-05T11:57:52.809425+00:00 app[web.1]: at require (internal/module.js:20:19)
2022-08-05T11:57:52.815363+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/connect-mongo/build/main/index.js:5:38)
2022-08-05T11:57:52.822611+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-08-05T11:57:52.822966+00:00 app[web.1]: npm ERR! errno 1
2022-08-05T11:57:52.826142+00:00 app[web.1]: npm ERR! backend#1.0.0 start: `node server.js`
2022-08-05T11:57:52.826182+00:00 app[web.1]: npm ERR! Exit status 1
2022-08-05T11:57:52.826329+00:00 app[web.1]: npm ERR!
2022-08-05T11:57:52.826388+00:00 app[web.1]: npm ERR! Failed at the backend#1.0.0 start script.
2022-08-05T11:57:52.826457+00:00 app[web.1]: npm ERR! This is probably not a problem with npm```
MongoStore.js
```class MongoStore extends session.Store {
constructor({ collectionName = 'sessions', ttl = 1209600, mongoOptions = {}, autoRemove = 'native', autoRemoveInterval = 10, touchAfter = 0, stringify = true, crypto, ...required }) {
super();
this.crypto = null;
debug('create MongoStore instance');
const options = {
collectionName,
ttl,
mongoOptions,
autoRemove,
autoRemoveInterval,
touchAfter,
stringify,
crypto: {
...{
secret: false,
algorithm: 'aes-256-gcm',
hashing: 'sha512',
encodeas: 'base64',
key_size: 32,
iv_size: 16,
at_size: 16,
},
...crypto,
},
...required,
};```
I think It's because you forgot to write two curly brackets } at the end of your program.
This kind of errors usually happens when you forgot to write a bracket or curly brackets.

ERROR : hosting Ecommerce web application in Heroku

Well i build a web application for an online e-commerce store project as a sample project. It was doing prefectly well until i decided to put it online in heroku and now the project keeps giving an error in heroku:
Error:
2022-05-31T09:50:32.498928+00:00 app[web.1]: Error: Cannot find module './debug'
2022-05-31T09:50:32.498928+00:00 app[web.1]: Require stack:
2022-05-31T09:50:32.498928+00:00 app[web.1]: - /app/node_modules/mquery/node_modules/debug/src/node.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mquery/node_modules/debug/src/index.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mquery/lib/mquery.js
2022-05-31T09:50:32.498929+00:00 app[web.1]: - /app/node_modules/mongoose/lib/promise_provider.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/helpers/promiseOrCallback.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/utils.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/statemachine.js
2022-05-31T09:50:32.498930+00:00 app[web.1]: - /app/node_modules/mongoose/lib/internal.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/lib/document.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/lib/index.js
2022-05-31T09:50:32.498931+00:00 app[web.1]: - /app/node_modules/mongoose/index.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/models/product.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/controllers/products.js
2022-05-31T09:50:32.498932+00:00 app[web.1]: - /app/Backend/routes/products.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: - /app/Backend/app.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: - /app/Backend/server.js
2022-05-31T09:50:32.498933+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-05-31T09:50:32.498934+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-05-31T09:50:32.498934+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mquery/node_modules/debug/src/node.js:14:28)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-05-31T09:50:32.498935+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-05-31T09:50:32.498936+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-05-31T09:50:32.498936+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-05-31T09:50:32.498937+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-05-31T09:50:32.498937+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-05-31T09:50:32.498937+00:00 app[web.1]: requireStack: [
2022-05-31T09:50:32.498937+00:00 app[web.1]: '/app/node_modules/mquery/node_modules/debug/src/node.js',
2022-05-31T09:50:32.498937+00:00 app[web.1]: '/app/node_modules/mquery/node_modules/debug/src/index.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mquery/lib/mquery.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/promise_provider.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/helpers/promiseOrCallback.js',
2022-05-31T09:50:32.498938+00:00 app[web.1]: '/app/node_modules/mongoose/lib/utils.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/statemachine.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/internal.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/document.js',
2022-05-31T09:50:32.498939+00:00 app[web.1]: '/app/node_modules/mongoose/lib/index.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/node_modules/mongoose/index.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/models/product.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/controllers/products.js',
2022-05-31T09:50:32.498940+00:00 app[web.1]: '/app/Backend/routes/products.js',
2022-05-31T09:50:32.498941+00:00 app[web.1]: '/app/Backend/app.js',
2022-05-31T09:50:32.498941+00:00 app[web.1]: '/app/Backend/server.js'
I'm worried to of what have happened this is the first time im learning this . Thanks in advance.
Git: GIT

Error while deploying node.js application to heroku (cannot find module dotenv, and npm ERR! errno 1)

I'm trying to upload my first node.js application to heroku. Build is showing successful, but the application cannot be opened in browser. Here is the logs tail of the deployment. I'm not quite sure where the problem(s) lie(s). All localhost routes are actually working when tested with postman. I'm using express generator, so the PORT is declared in .bin/www. I'm also using .env. I'm a bit lost about where to look next. Any suggestions? Many thanks!
2021-01-11T22:10:14.214188+00:00 app[web.1]: > finale-backend#0.0.0 start /app
2021-01-11T22:10:14.214189+00:00 app[web.1]: > node ./bin/www
2021-01-11T22:10:14.214189+00:00 app[web.1]:
2021-01-11T22:10:14.285451+00:00 app[web.1]: internal/modules/cjs/loader.js:818
2021-01-11T22:10:14.285453+00:00 app[web.1]: throw err;
2021-01-11T22:10:14.285453+00:00 app[web.1]: ^
2021-01-11T22:10:14.285454+00:00 app[web.1]:
2021-01-11T22:10:14.285454+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-01-11T22:10:14.285454+00:00 app[web.1]: Require stack:
2021-01-11T22:10:14.285455+00:00 app[web.1]: - /app/app.js
2021-01-11T22:10:14.285455+00:00 app[web.1]: - /app/bin/www
2021-01-11T22:10:14.285456+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
2021-01-11T22:10:14.285456+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
2021-01-11T22:10:14.285457+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-11T22:10:14.285457+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-11T22:10:14.285458+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:1)
2021-01-11T22:10:14.285458+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-11T22:10:14.285459+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-11T22:10:14.285460+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19) {
2021-01-11T22:10:14.285460+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-01-11T22:10:14.285461+00:00 app[web.1]: requireStack: [ '/app/app.js', '/app/bin/www' ]
2021-01-11T22:10:14.285461+00:00 app[web.1]: }
2021-01-11T22:10:14.301983+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-01-11T22:10:14.302357+00:00 app[web.1]: npm ERR! errno 1
2021-01-11T22:10:14.309690+00:00 app[web.1]: npm ERR! finale-backend#0.0.0 start: `node ./bin/www`
2021-01-11T22:10:14.309804+00:00 app[web.1]: npm ERR! Exit status 1
2021-01-11T22:10:14.309965+00:00 app[web.1]: npm ERR!
2021-01-11T22:10:14.310034+00:00 app[web.1]: npm ERR! Failed at the finale-backend#0.0.0 start script.
2021-01-11T22:10:14.310119+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-01-11T22:10:14.317026+00:00 app[web.1]:
2021-01-11T22:10:14.317243+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-11T22:10:14.317339+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-11T22_10_14_310Z-debug.log
2021-01-11T22:10:14.361923+00:00 heroku[web.1]: Process exited with status 1
2021-01-11T22:10:14.435764+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-11T22:10:14.439118+00:00 heroku[web.1]: State changed from crashed to starting
2021-01-11T22:10:16.805923+00:00 heroku[web.1]: Starting process with command `npm start`
2021-01-11T22:10:19.751944+00:00 app[web.1]:
2021-01-11T22:10:19.751961+00:00 app[web.1]: > finale-backend#0.0.0 start /app
2021-01-11T22:10:19.751962+00:00 app[web.1]: > node ./bin/www
2021-01-11T22:10:19.751963+00:00 app[web.1]:
2021-01-11T22:10:19.808881+00:00 app[web.1]: internal/modules/cjs/loader.js:818
2021-01-11T22:10:19.808883+00:00 app[web.1]: throw err;
2021-01-11T22:10:19.808883+00:00 app[web.1]: ^
2021-01-11T22:10:19.808883+00:00 app[web.1]:
2021-01-11T22:10:19.808884+00:00 app[web.1]: Error: Cannot find module 'dotenv'
2021-01-11T22:10:19.808884+00:00 app[web.1]: Require stack:
2021-01-11T22:10:19.808884+00:00 app[web.1]: - /app/app.js
2021-01-11T22:10:19.808885+00:00 app[web.1]: - /app/bin/www
2021-01-11T22:10:19.808885+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
2021-01-11T22:10:19.808885+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:667:27)
2021-01-11T22:10:19.808886+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-11T22:10:19.808886+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:1:1)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:999:30)
2021-01-11T22:10:19.808887+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-11T22:10:19.808888+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-11T22:10:19.808888+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-11T22:10:19.808889+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19) {
2021-01-11T22:10:19.808889+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-01-11T22:10:19.808889+00:00 app[web.1]: requireStack: [ '/app/app.js', '/app/bin/www' ]
2021-01-11T22:10:19.808890+00:00 app[web.1]: }
2021-01-11T22:10:19.834122+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-01-11T22:10:19.834754+00:00 app[web.1]: npm ERR! errno 1
2021-01-11T22:10:19.843644+00:00 app[web.1]: npm ERR! finale-backend#0.0.0 start: `node ./bin/www`
2021-01-11T22:10:19.843996+00:00 app[web.1]: npm ERR! Exit status 1
2021-01-11T22:10:19.844353+00:00 app[web.1]: npm ERR!
2021-01-11T22:10:19.844619+00:00 app[web.1]: npm ERR! Failed at the finale-backend#0.0.0 start script.
2021-01-11T22:10:19.844914+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-01-11T22:10:19.858827+00:00 app[web.1]:
2021-01-11T22:10:19.859298+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-01-11T22:10:19.859536+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-01-11T22_10_19_845Z-debug.log
2021-01-11T22:10:19.946324+00:00 heroku[web.1]: Process exited with status 1
2021-01-11T22:10:20.030800+00:00 heroku[web.1]: State changed from starting to crashed
2021-01-11T22:10:22.579029+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=XXXXXX.herokuapp.com request_id=28ed0f16-48b7-4edb-a4d4-bf5af57518a5 fwd="91.106.154.160" dyno= connect= service= status=503 bytes= protocol=https
2021-01-11T22:10:23.309377+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=XXXXXX.herokuapp.com request_id=967010fc-984e-49c7-a73e-9d9758907f49 fwd="91.106.154.160" dyno= connect= service= status=503 bytes= protocol=https
My package json looks like this:
{
"name": "finale-backend",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
"dependencies": {
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"debug": "~2.6.9",
"express": "~4.16.1",
"helmet": "^4.3.1",
"jsonwebtoken": "^8.5.1",
"logger": "0.0.1",
"morgan": "~1.9.1",
"nodemon": "^2.0.7",
"pg": "^8.5.1"
},
"devDependencies": {
"dotenv": "^8.2.0"
},
"engines": {
"node": "12.x"
}
}
And I require dotenv in my entry point app.js like this
require('dotenv').config();
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const cors = require('cors')
It seems like Heroku is not installing devDependencies by default. You may want to move dotenv to dependencies in your package.json and try again.
If you don't need dotenv in your production environment, you may want to remove the require altogether and use a different command to run your development server, as described here:
https://www.npmjs.com/package/dotenv#preload
node -r dotenv/config your_script.js
This will prevent your server from crashing in production when the dotenv dependency is not found on Heroku.
The reason because you are using dotenv in devDependencies. Change dotenv dependency to dependencies like this:
"dependencies": {
...,
"dotenv": "^8.2.0"
}

Express server working locally but crashing on heroku

My Node + Express server is working locally but not on Heroku.
Also worth mentioning I'm using heroku-postgres and ran these commands
heroku run knex migrate:latest -a myAppName
heroku run knex seed:latest -a myAppName
The commands ran successfully and I can see the seeded DB on Heroku.
What's the issue?
Now when I try to access the server, it just won't work because of some modules it can't find, but again it works perfectly on my end
I'm also deploying from my development-branch, haven't yet merged to master but that shouldn't be the problem.
Heroku Logs:
2019-11-20T19:57:57.678058+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-20T19:57:57.524659+00:00 app[web.1]: internal/modules/cjs/loader.js:895
2019-11-20T19:57:57.524683+00:00 app[web.1]: throw err;
2019-11-20T19:57:57.524685+00:00 app[web.1]: ^
2019-11-20T19:57:57.524686+00:00 app[web.1]:
2019-11-20T19:57:57.524689+00:00 app[web.1]: Error: Cannot find module '../../Users/Middlewares/validateUserID'
2019-11-20T19:57:57.524690+00:00 app[web.1]: Require stack:
2019-11-20T19:57:57.524692+00:00 app[web.1]: - /app/Issues/Routes/IssueRoutes.js
2019-11-20T19:57:57.524694+00:00 app[web.1]: - /app/api/server.js
2019-11-20T19:57:57.524695+00:00 app[web.1]: - /app/index.js
2019-11-20T19:57:57.524697+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
2019-11-20T19:57:57.524698+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:785:27)
2019-11-20T19:57:57.524700+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:57:57.524702+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:57:57.524703+00:00 app[web.1]: at Object.<anonymous> (/app/Issues/Routes/IssueRoutes.js:6:28)
2019-11-20T19:57:57.524704+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:57:57.524706+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:57:57.524707+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:57:57.524708+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14)
2019-11-20T19:57:57.524710+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:57:57.524711+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:57:57.524712+00:00 app[web.1]: at Object.<anonymous> (/app/api/server.js:10:21)
2019-11-20T19:57:57.524713+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:57:57.524715+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:57:57.524716+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:57:57.524717+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14) {
2019-11-20T19:57:57.524718+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-11-20T19:57:57.524720+00:00 app[web.1]: requireStack: [
2019-11-20T19:57:57.524721+00:00 app[web.1]: '/app/Issues/Routes/IssueRoutes.js',
2019-11-20T19:57:57.524722+00:00 app[web.1]: '/app/api/server.js',
2019-11-20T19:57:57.524724+00:00 app[web.1]: '/app/index.js'
2019-11-20T19:57:57.524725+00:00 app[web.1]: ]
2019-11-20T19:57:57.524726+00:00 app[web.1]: }
2019-11-20T19:57:57.533660+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-20T19:57:57.534079+00:00 app[web.1]: npm ERR! errno 1
2019-11-20T19:57:57.536043+00:00 app[web.1]: npm ERR! bettercity#1.0.0 start: `node index.js`
2019-11-20T19:57:57.536045+00:00 app[web.1]: npm ERR! Exit status 1
2019-11-20T19:57:57.536154+00:00 app[web.1]: npm ERR!
2019-11-20T19:57:57.536817+00:00 app[web.1]: npm ERR! Failed at the bettercity#1.0.0 start script.
2019-11-20T19:57:57.536821+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-20T19:57:57.563676+00:00 app[web.1]:
2019-11-20T19:57:57.564106+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-20T19:57:57.564508+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-20T19_57_57_537Z-debug.log
2019-11-20T19:57:57.659267+00:00 heroku[web.1]: Process exited with status 1
2019-11-20T19:58:25.000000+00:00 app[api]: Build started by user myEmail#mail.com
2019-11-20T19:59:21.041005+00:00 app[api]: Deploy a1b6ff8e by user myEmail#mail.com
2019-11-20T19:59:21.041005+00:00 app[api]: Release v20 created by user myEmail#mail.com
2019-11-20T19:59:21.000000+00:00 app[api]: Build succeeded
2019-11-20T19:59:22.528003+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-20T19:59:26.144682+00:00 heroku[web.1]: Starting process with command `npm start`
2019-11-20T19:59:29.286295+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-20T19:59:28.777609+00:00 app[web.1]:
2019-11-20T19:59:28.777626+00:00 app[web.1]: > bettercity#1.0.0 start /app
2019-11-20T19:59:28.777628+00:00 app[web.1]: > node index.js
2019-11-20T19:59:28.777629+00:00 app[web.1]:
2019-11-20T19:59:29.268829+00:00 heroku[web.1]: Process exited with status 1
2019-11-20T19:59:29.169740+00:00 app[web.1]: internal/modules/cjs/loader.js:895
2019-11-20T19:59:29.169765+00:00 app[web.1]: throw err;
2019-11-20T19:59:29.169766+00:00 app[web.1]: ^
2019-11-20T19:59:29.169767+00:00 app[web.1]:
2019-11-20T19:59:29.169779+00:00 app[web.1]: Error: Cannot find module '../../Users/Middlewares/validateUserID'
2019-11-20T19:59:29.169780+00:00 app[web.1]: Require stack:
2019-11-20T19:59:29.169781+00:00 app[web.1]: - /app/Issues/Routes/IssueRoutes.js
2019-11-20T19:59:29.169782+00:00 app[web.1]: - /app/api/server.js
2019-11-20T19:59:29.169783+00:00 app[web.1]: - /app/index.js
2019-11-20T19:59:29.169784+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
2019-11-20T19:59:29.169785+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:785:27)
2019-11-20T19:59:29.169786+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:59:29.169787+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:59:29.169788+00:00 app[web.1]: at Object.<anonymous> (/app/Issues/Routes/IssueRoutes.js:6:28)
2019-11-20T19:59:29.169789+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:59:29.169790+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:59:29.169791+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:59:29.169792+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14)
2019-11-20T19:59:29.169793+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:956:19)
2019-11-20T19:59:29.169794+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2019-11-20T19:59:29.169795+00:00 app[web.1]: at Object.<anonymous> (/app/api/server.js:10:21)
2019-11-20T19:59:29.169796+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2019-11-20T19:59:29.169797+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
2019-11-20T19:59:29.169798+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:914:32)
2019-11-20T19:59:29.169799+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:822:14) {
2019-11-20T19:59:29.169800+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2019-11-20T19:59:29.169801+00:00 app[web.1]: requireStack: [
2019-11-20T19:59:29.169802+00:00 app[web.1]: '/app/Issues/Routes/IssueRoutes.js',
2019-11-20T19:59:29.169803+00:00 app[web.1]: '/app/api/server.js',
2019-11-20T19:59:29.169804+00:00 app[web.1]: '/app/index.js'
2019-11-20T19:59:29.169805+00:00 app[web.1]: ]
2019-11-20T19:59:29.169806+00:00 app[web.1]: }
2019-11-20T19:59:29.179485+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-11-20T19:59:29.179812+00:00 app[web.1]: npm ERR! errno 1
2019-11-20T19:59:29.181606+00:00 app[web.1]: npm ERR! bettercity#1.0.0 start: `node index.js`
2019-11-20T19:59:29.181811+00:00 app[web.1]: npm ERR! Exit status 1
2019-11-20T19:59:29.182146+00:00 app[web.1]: npm ERR!
2019-11-20T19:59:29.182403+00:00 app[web.1]: npm ERR! Failed at the bettercity#1.0.0 start script.
2019-11-20T19:59:29.182699+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-11-20T19:59:29.198787+00:00 app[web.1]:
2019-11-20T19:59:29.199117+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-11-20T19:59:29.199119+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-11-20T19_59_29_183Z-debug.log
package.json
{
"name": "bettercity",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rodpa715/bettercity.git"
},
"author": "Patrick Rodrigues",
"license": "ISC",
"bugs": {
"url": "https://github.com/rodpa715/bettercity/issues"
},
"homepage": "https://github.com/rodpa715/bettercity#readme",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"helmet": "^3.21.2",
"jsonwebtoken": "^8.5.1",
"knex": "^0.20.2",
"node": "^13.1.0",
"pg": "^7.12.1"
},
"engines": {
"node": "^10.16.3",
"npm": "6.13.0"
},
"devDependencies": {
"jest": "^24.9.0",
"nodemon": "^1.19.4",
"supertest": "^4.0.2"
}
}
[SOLVED]
It seems as though GitHub doesn't track folder case-sensitivity change so even when I renamed the folders it didn't work. I copied everything into a new repo and it deployed successfully.
Try changing
const { validateUserID } = require("../../Users/Middlewares/validateUserID");
to
const { validateUserID } = require("../../users/Middlewares/validateUserID");
with a lowercase users
linux is case sensitive and it might be giving issues on a server but not on your machine if you have a mac.
Your paths to the routes are incorrect and node cannot find those in the Heroku filesystem.
Work off your current file using like './' so you update to:
const authRoutes = require("./../Authentication/Routes/AuthRoutes");

Resources