MonsterWimp757
MonsterWimp757

Reputation: 1217

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

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]: > [email protected] 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! [email protected] 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 [email protected] 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`

Upvotes: 0

Views: 1395

Answers (1)

Santiago Rebella
Santiago Rebella

Reputation: 2449

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

Upvotes: 1

Related Questions