Heroku Node.js应用程序崩溃| module.js:340错误

问题描述:

我的Heroku应用程序崩溃了,我相信在它到达Procfile之前。我在这里遇到了同样的问题:Heroku Node.js应用程序崩溃| module.js:340错误

Cannot execute Node.js app on Heroku successfully (crashes each time)

唯一的区别是,我的package.json文件有快递包括

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" 
    } 
} 

我试图在当地工头工具和一切工作正常。

我的主要weather.js文件包含:

server.listen(4000); 
console.log("Express server started on 4000"); 

任何帮助将不胜感激。

更新:Heroku的日志

`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` 
+1

那么,它可能不会TH e答案,但我在部署在heroku上的golang应用程序遇到类似问题。该应用程序崩溃,因为我手动设置端口,就像你一样。尝试将'server.listen(4000)'更改为'server.listen(process.env.PORT)'并让heroku决定使用哪个端口。如果它解决了问题,您可以使用heroku配置来设置端口:'heroku config:set PORT = 4000'。 – fakemeta 2014-08-28 15:33:37

+0

我只是试过,没有骰子,我会保持端口为process.env.PORT,以保证安全。谢谢。 – MonsterWimp757 2014-08-28 15:37:03

+1

你也可以用一些日志来更新你的问题。 'heroku logs' – fakemeta 2014-08-28 15:42:47

我看到了一些东西,你可以改善,因为在他的评论fakemeta状态,你应该使用Heroku的变量来监听端口,并有IP。

你也应该在你的package.json:

"scripts": { 
    "start": "node server.js" 
    }, 
    "main": "server.js" 

所以系统知道做什么,哪里是你Express服务器

// ---------- ---编辑---------------------------- //

你不能尝试部署没有node_modules文件夹?,一旦你推的Heroku将安装这些程序包,我的意思是,至少只是为了调试的目的

+0

你问我的快递服务器在哪里?我将这些行添加到我的package.json文件中,并且仍然有相同的错误消息。这个脚本区域是否由Procfile处理? – MonsterWimp757 2014-08-28 15:46:04

+0

不,我告诉你,你应该告诉系统你的服务器在哪里,据我所知是从你的package.json – 2014-08-28 16:39:29

+0

我已经更新package.json的那一节,我仍然有同样的问题 – MonsterWimp757 2014-08-28 17:35:58