Heroku Node.js App Crashing | module.js:340 error - javascript

My Heroku app is crashing, I believe before it even gets to the Procfile. I am experiencing the same problem as here:
Cannot execute Node.js app on Heroku successfully (crashes each time)
The only difference is that my package.json file has Express included
package.json
{
"name": "weathersocket",
"version": "0.0.1",
"description": "text based weather",
"main": "weather.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/agreen757/weathersocket.github.io"
},
"keywords": [
"demo",
"heroku",
"weather"
],
"author": "Adrian Green",
"license": "MIT",
"bugs": {
"url": "https://github.com/agreen757/weathersocket.github.io/issues"
},
"homepage": "https://github.com/agreen757/weathersocket.github.io",
"dependencies": {
"body-parser": "^1.6.6",
"consolidate": "^0.10.0",
"cookie-parser": "^1.3.2",
"express": "^4.8.6",
"mongodb": "^1.4.9",
"socket.io": "^1.0.6",
"swig": "^1.4.2"
}
}
I have tried to the foreman utility locally and everything works properly.
My main weather.js file contains:
server.listen(4000);
console.log("Express server started on 4000");
Any help would be greatly appreciated.
Update: Heroku logs
`2014-08-28T14:29:14.866955+00:00 heroku[web.1]: State changed from crashed to starting
2014-08-28T14:29:18.414238+00:00 app[web.1]:
2014-08-28T14:29:18.414259+00:00 app[web.1]: > node weather.js
2014-08-28T14:29:18.414257+00:00 app[web.1]: > weathersocket#10.3.1 start /app
2014-08-28T14:29:18.414260+00:00 app[web.1]:
2014-08-28T14:29:18.755300+00:00 app[web.1]:
2014-08-28T14:29:18.755380+00:00 app[web.1]: module.js:340
2014-08-28T14:29:18.755637+00:00 app[web.1]: throw err;
2014-08-28T14:29:18.755646+00:00 app[web.1]: ^
2014-08-28T14:29:18.757013+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2014-08-28T14:29:18.757015+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2014-08-28T14:29:18.757011+00:00 app[web.1]: Error: Cannot find module 'socket.io'
2014-08-28T14:29:18.757016+00:00 app[web.1]: at Module.require (module.js:364:17)
2014-08-28T14:29:18.757017+00:00 app[web.1]: at require (module.js:380:17)
2014-08-28T14:29:18.757019+00:00 app[web.1]: at Object.<anonymous> (/app/weather.js:6:10)
2014-08-28T14:29:18.757020+00:00 app[web.1]: at Module._compile (module.js:456:26)
2014-08-28T14:29:18.757022+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)
2014-08-28T14:29:18.757023+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-08-28T14:29:18.757025+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2014-08-28T14:29:18.757026+00:00 app[web.1]: at Function.Module.runMain (module.js:497:10)
2014-08-28T14:29:18.765774+00:00 app[web.1]:
2014-08-28T14:29:18.770873+00:00 app[web.1]: npm ERR!
2014-08-28T14:29:18.770460+00:00 app[web.1]: npm ERR! weathersocket#10.3.1 start: `node weather.js`
2014-08-28T14:29:18.770720+00:00 app[web.1]: npm ERR! Exit status 8
2014-08-28T14:29:18.770945+00:00 app[web.1]: npm ERR! Failed at the weathersocket#10.3.1 start script.
2014-08-28T14:29:18.771539+00:00 app[web.1]: npm ERR! This is most likely a problem with the weathersocket package,
2014-08-28T14:29:18.771696+00:00 app[web.1]: npm ERR! not with npm itself.
2014-08-28T14:29:18.771844+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2014-08-28T14:29:18.772002+00:00 app[web.1]: npm ERR! node weather.js
2014-08-28T14:29:18.772821+00:00 app[web.1]: npm ERR! System Linux 3.8.11-ec2
2014-08-28T14:29:18.773778+00:00 app[web.1]: npm ERR! npm -v 1.4.23
2014-08-28T14:29:18.772468+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2014-08-28T14:29:18.773030+00:00 app[web.1]: npm ERR! command "/app/vendor/node/bin/node" "/app/vendor/node/bin/npm" "start"
2014-08-28T14:29:18.773608+00:00 app[web.1]: npm ERR! node -v v0.10.31
2014-08-28T14:29:18.772297+00:00 app[web.1]: npm ERR! npm owner ls weathersocket
2014-08-28T14:29:18.775689+00:00 app[web.1]: npm ERR! Additional logging details can be found in:
2014-08-28T14:29:18.772151+00:00 app[web.1]: npm ERR! You can get their info via:
2014-08-28T14:29:18.773383+00:00 app[web.1]: npm ERR! cwd /app
2014-08-28T14:29:18.775539+00:00 app[web.1]: npm ERR!
2014-08-28T14:29:18.773965+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2014-08-28T14:29:18.776097+00:00 app[web.1]: npm ERR! not ok code 0
2014-08-28T14:29:18.775840+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2014-08-28T14:29:19.793237+00:00 heroku[web.1]: State changed from starting to crashed
2014-08-28T14:29:16.891824+00:00 heroku[web.1]: Starting process with command `npm start`
2014-08-28T14:29:19.781258+00:00 heroku[web.1]: Process exited with status 1`

I see a few things you could improve, as fakemeta states in his commentary, you should be using the heroku variables to listen port and to have the IP.
You should also include in your package.json:
"scripts": {
"start": "node server.js"
},
"main": "server.js"
So the system know what to do and where is your express server
//-------------EDIT----------------------------//
Cant you try to deploy without node_modules folder?, once you push heroku will install those packages, i mean at least just for debugging purposes

Related

How to fix nodemon "block-scoped declarations..." error?

This is my package.json file:
{
"name": "pro-mern-stack",
"version": "1.0.0",
"description": "first init",
"main": "index.js",
"scripts": {
"start": "nodemon server.js server.js",
"compile": "babel src --presets react,es2015 --out-dir static",
"watch": "babel src --presets react,es2015 --out-dir static --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Yusuf",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"mongodb": "latest"
},
"devDependencies": {
"express": "^4.17.1",
"nodemon": "^2.0.2"
}
}
I'M TRYING TO RUN npm start TO START THE WATCHER BUT I KEEP GETTING THIS ERROR:
> nodemon server.js server.js
C:\MERN\pro-mern-stack\node_modules\nodemon\lib\monitor\run.js:356
let sig = signal.replace('SIG', '');
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\MERN\pro-mern-stack\node_modules\nodemon\lib\monitor\index.js:2:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.5.0
npm ERR! npm v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! pro-mern-stack#1.0.0 start: `nodemon server.js server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pro-mern-stack#1.0.0 start script 'nodemon server.js server.js'.
npm ERR! This is most likely a problem with the pro-mern-stack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nodemon server.js server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs pro-mern-stack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls pro-mern-stack
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\mern\pro-mern-stack\npm-debug.log
I'm running with powershell on windows 10. I've tried installing globally, didn't work. Also have the latest version of nodemon. Please, how can i fix this? I've reinstalled nodemon several times, keep getting the same error, even when I run it directly in the console. Thanks!
I see issue in the npm script. You should just update it to nodemon server.js

Error: ENOENT: no such file or directory, `node src/index.js`

I am working in node Js. When im trying to load a file, with this lines:
key: fs.readFileSync('./localCerts/local.dev.key'),
cert: fs.readFileSync('./localCerts/local.dev.crt'),
This is error appeards when I try to rub application:
bou-frontend#0.0.1 start /Users/nikolatrajkovic/Desktop/projects/bou-frontend/bou-frontend
node src/index.js
fs.js:114
throw err;
^
Error: ENOENT: no such file or directory, open
'/Users/nikolatrajkovic/Desktop/projects/bou-frontend/bou-frontend/build/index.html'
at Object.openSync (fs.js:438:3)
at readFileSync (fs.js:343:35)
at Object. (/Users/nikolatrajkovic/Desktop/projects/bou-frontend/bou-frontend/src/ssr.js:34:22)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! bou-frontend#0.0.1 start: node
src/index.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the
bou-frontend#0.0.1 start script. npm ERR! This is probably not a
problem with npm. There is likely additional logging output above.
PACKAGE.json file:
scripts": {
"start": "node src/index.js",
}
Any advice or help is welcome.

Error when running "npm start"?

I have started with electron today and followed a guide to create a simple application browser window and I ran npm start in the command window and it displayed a lot of errors after I had entered it, I have posted the information below and my code.
Console error:
C:\Users\Administrator\Desktop\electron>npm start
> breef#1.0.0 start C:\Users\Administrator\Desktop\electron
> node index.js
module.js:471
throw err;
^
Error: Cannot find module 'app'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Administrator\Desktop\electron\index.js:1:73)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! breef#1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the breef#1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the breef package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs breef
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls breef
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Administrator\Desktop\electron\npm-debug.log
Here is my package.json:
{
"name": "breef",
"version": "1.0.0",
"description": "A simple chat application.",
"main": "index.js",
"dependencies": {
"electron": "^1.4.12"
},
"devDependencies": {},
"scripts": {
"test": "breeftestcmd",
"start": "node index.js"
},
"keywords": [
"breef"
],
"author": "Sage & Sh4wn",
"license": "ISC"
}
Here is my index.js:
var app = require("app")
var browserWindow = require("browser-window")
app.on('ready', function() {
var mainWindow = new browserWindow({
width: 800,
height: 600
})
mainWindow.loadUrl('http://google.com');
})
If app is a module, it's missing in your package.json. If not, you should use a path to require it
var app = require('./app');
The guide you followed is out of date, as of Electron v1.0.0 the way built-in Electron modules are imported has changed. This is the correct way:
const {app, BrowserWindow} = require("electron")
You may also find it beneficial to read the previous question that covered this topic: What's the proper way to require in Node.js?

Error: Cannot find module './'

I stumbled upon this error when trying to start my application via NPM start. I am not sure where the problem lies, because it worked fine in my other computer (I unzip the file to this computer ran, npm install just in case and then tried to start it, but then the following error is thrown below).
Any help would be appreciated.
module.js:340
throw err;
^
Error: Cannot find module './'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/mnt/c/Users/Jonathan/Desktop/client/<NAME>/node_modules/.bin/electron:3:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
npm ERR! Linux 3.4.0+
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v0.10.46
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! <NAME>#0.0.0 start: `electron main.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the <NAME>#0.0.0 start script 'electron main.js'.
npm ERR! This is most likely a problem with the <NAME> package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! electron main.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs <NAME>
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls <NAME>
npm ERR! There is likely additional logging output above.
package.json
{
"name": "<NAME>",
"version": "0.0.0",
"description": "[..]",
"main": "index.js",
"build": {
"appId": "test.321",
"app-category-type": "your.app.category.type",
"win": {
"iconUrl": "http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png"
}
},
"scripts": {
"start": "electron main.js",
"postinstall": "install-app-deps",
"pack": "build --dir",
"dist": "build"
},
"author": "john#gmail.com>",
"license": "ISC",
"devDependencies": {
"electron": "^1.3.3",
"electron-installer-squirrel-windows": "^1.3.0",
"electron-packager": "^7.5.1"
}
}
UPDATE
After solving the above error, the following error is thrown
I am running this through bash on windows 10, and have tried to install all required libraries to get the electron app to start via npm start on windows (works fine in my ubuntu)
electron main.js
[8002:0814/084446:FATAL:render_sandbox_host_linux.cc(40)] Check failed: 0 == shutdown(renderer_socket_, SHUT_RD). shutdown: Invalid argument
#0 0x000001e098ce <unknown>
#1 0x000001e1f4db <unknown>
#2 0x000001e1fa9d <unknown>
#3 0x000002892fc2 <unknown>
#4 0x00000265e599 <unknown>
#5 0x000002664b5f <unknown>
#6 0x00000265dc36 <unknown>
#7 0x000001204157 <unknown>
#8 0x000001202c30 <unknown>
#9 0x0000033a9470 main
#10 0x7fe5ec701f45 __libc_start_main
#11 0x000000575039 <unknown>
The shutdown check fail is a known issue. Electron runs just fine as a native Windows app, so just do that instead of over-complicating things with Bash on Windows.

Heroku, mLab and Node.js: Application Error - Mongoose

I am new to Node.js and Heroku and am trying to host my first application on Heroku but am having issues with the deployment. I have been following this tutorial to deploy the app: https://scotch.io/tutorials/use-mongodb-with-a-node-application-on-heroku
In cmd prompt I have done the following:
1. heroku
2. heroku login
3. heroku create app
4. git push heroku master
5. heroku ps:scale web=1
6. heroku open
7. heroku logs --tail (below is a list of the log messages I see after heroku open)
On my mLab console I have created a database, collection and user and defined my mongo URI as the following:
'mongodb://admin:********#asdf1234.mlab.com:13122/app'
If I start my Node app locally, I can successfully create data into this database, but when I try to access my app from Heroku, I get the application error webpage. I know I must be missing a steps somewhere? I believe this is related to Mongoose?
2016-05-03T02:27:29.458496+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-03T02:27:33.077531+00:00 heroku[web.1]: Starting process with command `npm start`
2016-05-03T02:27:35.383818+00:00 app[web.1]:
2016-05-03T02:27:35.383872+00:00 app[web.1]: > app#0.0.0 start /app
2016-05-03T02:27:35.383878+00:00 app[web.1]: > node ./bin/www
2016-05-03T02:27:35.383887+00:00 app[web.1]:
2016-05-03T02:27:35.587955+00:00 app[web.1]: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
2016-05-03T02:27:35.589136+00:00 app[web.1]: js-bson: Failed to load c++ bson extension, using pure JS version
2016-05-03T02:27:35.947930+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2016-05-03T02:27:35.947945+00:00 app[web.1]: designed for a production environment, as it will leak
2016-05-03T02:27:35.947946+00:00 app[web.1]: memory, and will not scale past a single process.
2016-05-03T02:27:35.986323+00:00 app[web.1]:
2016-05-03T02:27:35.986338+00:00 app[web.1]: /app/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
2016-05-03T02:27:35.986339+00:00 app[web.1]: process.nextTick(function() { throw err; })
2016-05-03T02:27:35.986341+00:00 app[web.1]: ^
2016-05-03T02:27:35.986344+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:27017
2016-05-03T02:27:35.986345+00:00 app[web.1]: at Object.exports._errnoException (util.js:893:11)
2016-05-03T02:27:35.986346+00:00 app[web.1]: at exports._exceptionWithHostPort (util.js:916:20)
2016-05-03T02:27:35.986347+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1075:14)
2016-05-03T02:27:35.997520+00:00 app[web.1]:
2016-05-03T02:27:36.009323+00:00 app[web.1]: npm ERR! Linux 3.13.0-79-generic
2016-05-03T02:27:36.009834+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-05-03T02:27:36.010139+00:00 app[web.1]: npm ERR! node v5.11.0
2016-05-03T02:27:36.010913+00:00 app[web.1]: npm ERR! npm v3.8.6
2016-05-03T02:27:36.011252+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-05-03T02:27:36.011483+00:00 app[web.1]: npm ERR! app#0.0.0 start: `node ./bin/www`
2016-05-03T02:27:36.011697+00:00 app[web.1]: npm ERR! Exit status 1
2016-05-03T02:27:36.011937+00:00 app[web.1]: npm ERR!
2016-05-03T02:27:36.012344+00:00 app[web.1]: npm ERR! Failed at the app#0.0.0 start script 'node ./bin/www'.
2016-05-03T02:27:36.012587+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-05-03T02:27:36.012830+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the app package,
2016-05-03T02:27:36.013080+00:00 app[web.1]: npm ERR! not with npm itself.
2016-05-03T02:27:36.013296+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-05-03T02:27:36.013522+00:00 app[web.1]: npm ERR! node ./bin/www
2016-05-03T02:27:36.013730+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-05-03T02:27:36.013943+00:00 app[web.1]: npm ERR! npm bugs app
2016-05-03T02:27:36.014152+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-05-03T02:27:36.014360+00:00 app[web.1]: npm ERR! npm owner ls app
2016-05-03T02:27:36.014579+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-05-03T02:27:36.021124+00:00 app[web.1]:
2016-05-03T02:27:36.021429+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-05-03T02:27:36.021644+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-05-03T02:27:36.772785+00:00 heroku[web.1]: Process exited with status 1
2016-05-03T02:27:36.779023+00:00 heroku[web.1]: State changed from starting to crashed
My package.json file looks like this if that helps:
{
"name": "app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "~1.13.2",
"connect-flash": "^0.1.1",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"express-session": "^1.13.0",
"jade": "~1.11.0",
"mongodb": "~1.4.4",
"mongoose": "^4.4.6",
"monk": "~1.0.1",
"morgan": "~1.6.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"serve-favicon": "~2.3.0"
}
}
Thanks for the help!
EDIT:
All I was missing was the node version in my package.json, the following fixed it for me:
"engines": {
"node": "4.3.2"
},
The following error:
Error: connect ECONNREFUSED 127.0.0.1:27017
Basically says it's trying to connect to MongoDB on 127.0.0.1 which would be the Heroku container not mLab, are you sure you are reading the MongoDB url from Process.env and trying to connect to that url?

Categories

Resources