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
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.
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?
I have used this code with my node.js application with express but when uploading to Heroku I get an error when running.
2016-09-28T11:01:40.502448+00:00 app[web.1]: /app/routes/index.js:146
2016-09-28T11:01:40.502467+00:00 app[web.1]: app.use(({method, url}, rsp, next) => {
2016-09-28T11:01:40.502468+00:00 app[web.1]: ^
2016-09-28T11:01:40.502468+00:00 app[web.1]:
2016-09-28T11:01:40.502469+00:00 app[web.1]: SyntaxError: Unexpected token {
2016-09-28T11:01:40.502469+00:00 app[web.1]: at exports.runInThisContext (vm.js:53:16)
2016-09-28T11:01:40.502470+00:00 app[web.1]: at Module._compile (module.js:387:25)
2016-09-28T11:01:40.502471+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
2016-09-28T11:01:40.502471+00:00 app[web.1]: at Module.load (module.js:357:32)
2016-09-28T11:01:40.502472+00:00 app[web.1]: at Function.Module._load (module.js:314:12)
2016-09-28T11:01:40.502473+00:00 app[web.1]: at Module.require (module.js:367:17)
2016-09-28T11:01:40.502473+00:00 app[web.1]: at require (internal/module.js:20:19)
2016-09-28T11:01:40.502474+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:8:14)
2016-09-28T11:01:40.502474+00:00 app[web.1]: at Module._compile (module.js:413:34)
2016-09-28T11:01:40.502475+00:00 app[web.1]: at Object.Module._extensions..js (module.js:422:10)
My code is
app.use(({method, url}, rsp, next) => {
rsp.on('finish', () => {
console.log(`${rsp.statusCode} ${method} ${url}`);
});
next();
});
Any help would be much appreciated
In your package.json, do you specify the node engine?
"engines": {
"node": "6.5.0"
}
I would have just added this as a comment, but I don't have enough rep.