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
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 `
I used 'node-adodb' nodejs module with .mdb database. Here is my code.
const ADODB = require('node-adodb');
const connection = ADODB.open(`Provider=Microsoft.Jet.OLEDB.4.0;Data Source=${__dirname}/data/Database.mdb;`);
module.exports = { connection : connection };
This is worked on a local and throws the following error after hosted on Heroku.
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
2020-04-23T21:53:16.421683+00:00 app[web.1]: ^
2020-04-23T21:53:16.421683+00:00 app[web.1]:
2020-04-23T21:53:16.421684+00:00 app[web.1]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
2020-04-23T21:53:16.421684+00:00 app[web.1]: at validateString (internal/validators.js:117:11)
2020-04-23T21:53:16.421685+00:00 app[web.1]: at Object.join (path.js:1039:7)
2020-04-23T21:53:16.421686+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/node-adodb/lib/engine.js:16:24)
2020-04-23T21:53:16.421686+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1156:30)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:1000:32)
2020-04-23T21:53:16.421687+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:899:14)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1042:19)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18)
2020-04-23T21:53:16.421688+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/node-adodb/index.js:11:16) {
2020-04-23T21:53:16.421689+00:00 app[web.1]: code: 'ERR_INVALID_ARG_TYPE'
2020-04-23T21:53:16.421689+00:00 app[web.1]: }
I am trying to deploy an application to Heroku, but after deployment in the logs I get the following error:
2017-08-09T09:32:39.071603+00:00 app[web.1]:
2017-08-09T09:32:39.876049+00:00 app[web.1]: /app/main.js:38
2017-08-09T09:32:39.876059+00:00 app[web.1]: app.set('port', (process.env.PORT || 5000));
2017-08-09T09:32:39.876060+00:00 app[web.1]: ^
2017-08-09T09:32:39.876060+00:00 app[web.1]:
2017-08-09T09:32:39.876063+00:00 app[web.1]: TypeError: Cannot read property 'PORT' of undefined
2017-08-09T09:32:39.876063+00:00 app[web.1]: at Object.<anonymous> (/app/main.js:38:29)
2017-08-09T09:32:39.876064+00:00 app[web.1]: at Module._compile (module.js:570:32)
2017-08-09T09:32:39.876065+00:00 app[web.1]: at Object.Module._extensions..js (module.js:579:10)
2017-08-09T09:32:39.876065+00:00 app[web.1]: at Module.load (module.js:487:32)
2017-08-09T09:32:39.876068+00:00 app[web.1]: at tryModuleLoad (module.js:446:12)
2017-08-09T09:32:39.876069+00:00 app[web.1]: at Function.Module._load (module.js:438:3)
2017-08-09T09:32:39.876069+00:00 app[web.1]: at Module.runMain (module.js:604:10)
2017-08-09T09:32:39.876070+00:00 app[web.1]: at run (bootstrap_node.js:389:7)
2017-08-09T09:32:39.876070+00:00 app[web.1]: at startup (bootstrap_node.js:149:9)
2017-08-09T09:32:39.876071+00:00 app[web.1]: at bootstrap_node.js:504:3
I get the same error when I try to run the application locally
11:26:03 web.1 | var port = process.env.PORT || 5000;
11:26:03 web.1 | ^
11:26:03 web.1 | TypeError: Cannot read property 'PORT' of undefined
Does someone know what am I doing wrong?
While deploying a Node application to Heroku I'm receiving the following error message. Any ideas what might cause it?
2016-09-19T09:44:06.497018+00:00 app[web.1]: "stack": [
2016-09-19T09:44:06.497020+00:00 app[web.1]: "TypeError: options.mongooseConnection.once is not a function",
2016-09-19T09:44:06.497021+00:00 app[web.1]: " at MongoStore (/app/node_modules/connect-mongo/src/index.js:91:48)",
2016-09-19T09:44:06.497021+00:00 app[web.1]: " at Object. (/app/app/session/index.js:14:17)",
2016-09-19T09:44:06.497022+00:00 app[web.1]: " at Module._compile (module.js:413:34)",
2016-09-19T09:44:06.497022+00:00 app[web.1]: " at Object.Module._extensions..js (module.js:422:10)",
2016-09-19T09:44:06.497023+00:00 app[web.1]: " at Module.load (module.js:357:32)",
2016-09-19T09:44:06.497023+00:00 app[web.1]: " at Function.Module._load (module.js:314:12)",
2016-09-19T09:44:06.497024+00:00 app[web.1]: " at Module.require (module.js:367:17)",
2016-09-19T09:44:06.497024+00:00 app[web.1]: " at require (internal/module.js:20:19)",
2016-09-19T09:44:06.497025+00:00 app[web.1]: " at Object. (/app/app/index.js:16:15)",
2016-09-19T09:44:06.497025+00:00 app[web.1]: " at Module._compile (module.js:413:34)",
2016-09-19T09:44:06.497026+00:00 app[web.1]: " at Object.Module._extensions..js (module.js:422:10)",
2016-09-19T09:44:06.497027+00:00 app[web.1]: " at Module.load (module.js:357:32)",
2016-09-19T09:44:06.497027+00:00 app[web.1]: " at Function.Module._load (module.js:314:12)",
2016-09-19T09:44:06.497028+00:00 app[web.1]: " at Module.require (module.js:367:17)",
2016-09-19T09:44:06.497028+00:00 app[web.1]: " at require (internal/module.js:20:19)",
2016-09-19T09:44:06.497029+00:00 app[web.1]: " at Object. (/app/server.js:4:17)",
2016-09-19T09:44:06.497029+00:00 app[web.1]: " at Module._compile (module.js:413:34)",
2016-09-19T09:44:06.497030+00:00 app[web.1]: " at Object.Module._extensions..js (module.js:422:10)",
2016-09-19T09:44:06.497030+00:00 app[web.1]: " at Module.load (module.js:357:32)",
2016-09-19T09:44:06.497031+00:00 app[web.1]: " at Function.Module._load (module.js:314:12)",
2016-09-19T09:44:06.497032+00:00 app[web.1]: " at Function.Module.runMain (module.js:447:10)",
2016-09-19T09:44:06.497032+00:00 app[web.1]: " at startup (node.js:148:18)"
2016-09-19T09:44:06.497033+00:00 app[web.1]: ],
2016-09-19T09:44:06.497033+00:00 app[web.1]: "level": "error",
2016-09-19T09:44:06.497034+00:00 app[web.1]: "message": "uncaughtException: options.mongooseConnection.once is not a function"
2016-09-19T09:44:06.497035+00:00 app[web.1]: }
I think you are creating mongoose connection with connect not with createConnection method that's why you are getting this error.
.createConnection() returns a Connection instance.
.connect() returns the global mongoose instance.
Then if you want to use once method then you have to use createConnection method instead of connect method
var db = mongoose.createConnection('MongoDB URL');
db.once('open', function() { ... });