Error: Cannot find module - Working locally but not on Heroku - node.js

I am running a node application that I cloned from my Heroku container. locally, it runs and the app operates from localhost:3000.
However when I deploy the app using git deploy to heroku, it starts and then immediately crashes. The heroku log is pasted below.
I can't work out why I am getting this error?
I've tried updating npm, deleteing node modules.
rm -rf node_modules
npm i core-util-is
npm install -g npm#latest
The heroku log looks like:
2019-06-24T15:35:26.071317+00:00 app[web.1]: > node index.js
2019-06-24T15:35:26.071318+00:00 app[web.1]:
2019-06-24T15:35:26.251019+00:00 app[web.1]: internal/modules/cjs/loader.js:638
2019-06-24T15:35:26.251023+00:00 app[web.1]: throw err;
2019-06-24T15:35:26.251024+00:00 app[web.1]: ^
2019-06-24T15:35:26.251026+00:00 app[web.1]:
2019-06-24T15:35:26.251027+00:00 app[web.1]: Error: Cannot find module './putty'
2019-06-24T15:35:26.251031+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
2019-06-24T15:35:26.251033+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:562:25)
2019-06-24T15:35:26.251034+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:690:17)
2019-06-24T15:35:26.251036+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-06-24T15:35:26.251037+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/sshpk/lib/formats/auto.js:18:13)
2019-06-24T15:35:26.251039+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:776:30)
2019-06-24T15:35:26.251040+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
2019-06-24T15:35:26.251041+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-06-24T15:35:26.251043+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-06-24T15:35:26.251044+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-06-24T15:35:26.259163+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-06-24T15:35:26.259707+00:00 app[web.1]: npm ERR! errno 1
2019-06-24T15:35:26.261454+00:00 app[web.1]: npm ERR! hello#1.0.0 start: `node index.js`
2019-06-24T15:35:26.261645+00:00 app[web.1]: npm ERR! Exit status 1
2019-06-24T15:35:26.261955+00:00 app[web.1]: npm ERR!
2019-06-24T15:35:26.262153+00:00 app[web.1]: npm ERR! Failed at the hello#1.0.0 start script.
2019-06-24T15:35:26.262343+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-06-24T15:35:26.270567+00:00 app[web.1]:
2019-06-24T15:35:26.270795+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-06-24T15:35:26.270955+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2019-06-24T15_35_26_264Z-debug.log

I've deleted the package.json and node_modules and ran
npm init
then reinstalled the packages required, it now works.

I ran into this same issue and in my case was able to resolve by moving the alleged "missing" module from devDependencies to dependencies in package.json. For whatever reason, it didn't matter that it was saved in devDependencies locally but caused an error on Heroku until reinstalling as a regular dependency.

Related

Unsure as to why I'm getting an error and why it doesn't start upon starting express.js

My express.js is unable to start upon typing npm start and I don't understand why it's happening, here's my error log:
C:\Users\simer\Desktop\API-workshop>npm start
> api-workshop#0.0.0 start C:\Users\simer\Desktop\API-workshop
> node ./bin/www
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'http-errors'
Require stack:
- C:\Users\simer\Desktop\API-workshop\app.js
- C:\Users\simer\Desktop\API-workshop\bin\www
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\Users\simer\Desktop\API-workshop\app.js:1:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\simer\\Desktop\\API-workshop\\app.js',
'C:\\Users\\simer\\Desktop\\API-workshop\\bin\\www'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api-workshop#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api-workshop#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\simer\AppData\Roaming\npm-cache\_logs\2022-01-19T21_07_47_160Z-debug.log
Does anyone know what I should do?
You need to install Your package - http-errors in root project directory.
npm install http-errors
Try to run again npm start

There is a problem when running a node application on ubuntu 18.04

I am trying to run a node site on an azure VM but I get this error when running > SkyCrypt#1.0.0 start
> node init && node index
internal/modules/cjs/loader.js:1109
throw err;
^
SyntaxError: /home/nim1com/SkyCrypt/credentials.json: Unexpected token v in JSON at position 216
at parse (<anonymous>)
at Object.Module._extensions..json (internal/modules/cjs/loader.js:1106:22)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/home/nim1com/SkyCrypt/init.js:15:21)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! SkyCrypt#1.0.0 start: `node init && node index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the SkyCrypt#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/nim1com/.npm/_logs/2021-01-19T09_41_40_472Z-debug.log```
What would be the answer to this problem? I have tried deleting package-lock.json and node_modules
credentials.json
{
"hypixel_api_key": "26ed366f-80ed-4b49-b912-ef46292c6225",
"recaptcha_site_key": "",
"recaptcha_secret_key": "",
"dbUrl": "mongodb+srv://dbStats:*********#cluster0.4kwsp.mongodb.net/test?retryWrites=true&w=majority",
"dbName": vmstats",
"session_secret": "36e47c144b9b9b3e0b9c8bf24c6ac2860c0f76a55b74dcea4007bf355af76789"
}
It seems your /home/nim1com/SkyCrypt/credentials.json file need to be corrected ...
read the error its complaining about the v in "dbName": vmstats", because is not valid json – Lawrence Cherone

Express-getting this error message trying to run server

I'm trying to run the server on the back-end of a project I'm doing and I keep getting this error message and it stops the server from running. I installed express generator if that makes any difference
> server#0.0.0 start /Users/username/Desktop/project/server
> node ./bin/www
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'http-errors'
Require stack:
- /Users/username/Desktop/project/server/main/app.js
- /Users/username/Desktop/project/server/bin/www
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:747:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/username/Desktop/project/server/main/app.js:1:19)
at Module._compile (internal/modules/cjs/loader.js:1085:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:791:14)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/username/Desktop/project/server/main/app.js',
'/Users/username/Desktop/project/server/bin/www'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! server#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the server#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/username/.npm/_logs/2020-11-13T03_27_43_635Z-debug.log
It clearly says Error: Cannot find module 'http-errors', so you probably don't have the package installed locally. Run npm i http-errors to download it.
Alternatively, if you'd like to save the package as a dependency in your project, run npm i http-errors --save

Having Problems with Node JS and AWS Elastic Beanstalk

I am getting the flowing errors when I try to build out my app in elasitcbeanstalk
var/log/nodejs/nodejs.log
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/var/app/current/index.js:1:17)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
> app#1.0.0 start /var/app/current
> node index.js
internal/modules/cjs/loader.js:638
throw err;
Image of Elasticbeanstak Config Files
My workspace
Try in NodeCommand with : "npm install && npm run start"

Deploying Vue app to Heroku, cannot find module shelljs

I am trying to deploy a vue template to our heroku instance. I have setup the procfile to call the right build script but am getting this.
Error: Cannot find module 'shelljs'
And the logs from it are:
2017-10-19T18:14:59.663986+00:00 heroku[web.1]: State changed from crashed to starting
2017-10-19T18:15:05.595940+00:00 heroku[web.1]: Starting process with command `npm run dev`
2017-10-19T18:15:13.354029+00:00 app[web.1]:
2017-10-19T18:15:13.354061+00:00 app[web.1]: > genesisui-vue#1.8.4 dev /app
2017-10-19T18:15:13.354061+00:00 app[web.1]: > node build/dev-server.js
2017-10-19T18:15:13.354062+00:00 app[web.1]:
2017-10-19T18:15:13.882843+00:00 app[web.1]: module.js:529
2017-10-19T18:15:13.882854+00:00 app[web.1]: throw err;
2017-10-19T18:15:13.882855+00:00 app[web.1]: ^
2017-10-19T18:15:13.882855+00:00 app[web.1]:
2017-10-19T18:15:13.882856+00:00 app[web.1]: Error: Cannot find module 'shelljs'
2017-10-19T18:15:13.882857+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:527:15)
2017-10-19T18:15:13.882858+00:00 app[web.1]: at Function.Module._load (module.js:476:23)
2017-10-19T18:15:13.882859+00:00 app[web.1]: at Module.require (module.js:568:17)
2017-10-19T18:15:13.882859+00:00 app[web.1]: at require (internal/module.js:11:18)
2017-10-19T18:15:13.882860+00:00 app[web.1]: at Object.<anonymous> (/app/build/check-versions.js:4:13)
2017-10-19T18:15:13.882860+00:00 app[web.1]: at Module._compile (module.js:624:30)
2017-10-19T18:15:13.882861+00:00 app[web.1]: at Object.Module._extensions..js (module.js:635:10)
2017-10-19T18:15:13.882861+00:00 app[web.1]: at Module.load (module.js:545:32)
2017-10-19T18:15:13.882862+00:00 app[web.1]: at tryModuleLoad (module.js:508:12)
2017-10-19T18:15:13.882863+00:00 app[web.1]: at Function.Module._load (module.js:500:3)
2017-10-19T18:15:13.894056+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-10-19T18:15:13.894488+00:00 app[web.1]: npm ERR! errno 1
2017-10-19T18:15:13.896140+00:00 app[web.1]: npm ERR! genesisui-vue#1.8.4 dev: `node build/dev-server.js`
2017-10-19T18:15:13.896314+00:00 app[web.1]: npm ERR! Exit status 1
2017-10-19T18:15:13.896580+00:00 app[web.1]: npm ERR!
2017-10-19T18:15:13.896777+00:00 app[web.1]: npm ERR! Failed at the genesisui-vue#1.8.4 dev script.
2017-10-19T18:15:13.896948+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-10-19T18:15:15.163061+00:00 app[web.1]:
2017-10-19T18:15:15.166845+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-10-19T18:15:15.166959+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-10-19T18_15_13_902Z-debug.log
2017-10-19T18:15:15.282631+00:00 heroku[web.1]: Process exited with status 1
2017-10-19T18:15:15.299772+00:00 heroku[web.1]: State changed from starting to crashed
Any leads would be very grateful!!!
npm install shelljs --save
git commit - m “your comment”
git push -u origin master
git push heroku master

Resources