2015-06-27 130 views
0

我一直在本地开发NodeJS/MongoDB应用程序,它工作正常,直到我尝试在Heroku上使用MongoLab。我有一个MongoLab帐户和数据库加载了集合,就像我的本地实例一样,并且在Heroku实例上使用了process.env.MONGOLAB_URI。当它在Heroku上运行时,该应用程序启动正常,服务于index.html页面,没有错误,并且数据库连接。我可以将从数据库中提取的数据记录到应用程序内存中,以显示它正确加载。但是在用户连接后大约5-10秒后,应用程序崩溃。Mongo npm冲突

我试过搞乱我的package.json,重新安装npm等,但都没有奏效。这里是我的Heroku的日志:

2015-06-27T17:37:01.640126+00:00 heroku[web.1]: Starting process with command `npm start` 
2015-06-27T17:37:03.027506+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY) 
2015-06-27T17:37:03.027536+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1 
2015-06-27T17:37:03.502229+00:00 app[web.1]: 
2015-06-27T17:37:03.502235+00:00 app[web.1]: > [email protected] start /app 
2015-06-27T17:37:03.502237+00:00 app[web.1]: > node server 
2015-06-27T17:37:03.502239+00:00 app[web.1]: 
2015-06-27T17:37:04.126284+00:00 app[web.1]: Server started. 
2015-06-27T17:37:04.575396+00:00 heroku[web.1]: State changed from starting to up 
2015-06-27T17:37:48.710857+00:00 heroku[router]: at=info method=GET path="/" host=myappname.herokuapp.com request_id=0a6b03e0-1704-428a-bb8e-f633fc7fab78 fwd="67.188.41.245" dyno=web.1 connect=1ms service=36ms status=200 bytes=5032 
2015-06-27T17:37:48.823086+00:00 heroku[router]: at=info method=GET path="/styles.css" host=myappname.herokuapp.com request_id=fcf6fca2-7057-4ad5-a506-d7f1a8fb743d fwd="67.188.41.245" dyno=web.1 connect=2ms service=8ms status=200 bytes=9866 
2015-06-27T17:37:48.936874+00:00 heroku[router]: at=info method=GET path="/util 
ities.js" host=myappname.herokuapp.com request_id=799cafdc-d785-495c-9009-a44c6bb4b94d fwd="67.188.41.245" dyno=web.1 connect=1ms service=2ms status=200 bytes=2158 
2015-06-27T17:37:48.936736+00:00 heroku[router]: at=info method=GET path="/models/app.js" host=myappname.herokuapp.com request_id=14582139-154f-406e-a805-4ff7264764dd fwd="67.188.41.245" dyno=web.1 connect=1ms service=11ms status=200 bytes=1042 
2015-06-27T17:37:48.926522+00:00 heroku[router]: at=info method=GET path="/views/index.js" host=myappname.herokuapp.com request_id=4632908e-f636-403e-9652-cbfcbda70ac7 fwd="67.188.41.245" dyno=web.1 connect=1ms service=4ms status=200 bytes=409 
2015-06-27T17:37:48.929183+00:00 heroku[router]: at=info method=GET path="/controllers/index.js" host=myappname.herokuapp.com request_id=c01d0952-b527-4887-8b38-5bfcbc3e781a fwd="67.188.41.245" dyno=web.1 connect=1ms service=2ms status=200 bytes=3953 
2015-06-27T17:37:48.926427+00:00 heroku[router]: at=info method=GET path="/framework.js" host=myappname.herokuapp.com request_id=ee1fbd0c-0b07-40ff-973d-0ad3fee28099 fwd="67.188.41.245" dyno=web.1 connect=1ms service=4ms status=200 bytes=2298 
2015-06-27T17:37:48.956359+00:00 heroku[router]: at=info method=GET path="/socket.io/socket.io.js" host=myappname.herokuapp.com request_id=862db6cc-f33f-45f4-8a5b-e09625c81209 fwd="67.188.41.245" dyno=web.1 connect=1ms service=38ms status=200 bytes=174134 
2015-06-27T17:37:49.464937+00:00 heroku[router]: at=info method=GET path="/assets/images/logo.png" host=myappname.herokuapp.com request_id=5c3a300e-2cb1-4ed0-a3c5-322982a477f5 fwd="67.188.41.245" dyno=web.1 connect=1ms service=19ms status=200 bytes=120815 
2015-06-27T17:37:49.548259+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1435426663905-0" host=myappname.herokuapp.com request_id=055c7320-61bc-48a8-a7bd-ef8243002da6 fwd="67.188.41.245" dyno=web.1 connect=2ms service=9ms status=200 bytes=306 
2015-06-27T17:37:49.659941+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1435426664025-1&sid=tpgz2B5g5izndmQ5AAAA" host=myappname.herokuapp.com request_id=e89c7cd4-ce07-43e2-b0a3-4bda3f52dfff fwd="67.188.41.245" dyno=web.1 connect=2ms service=3ms status=200 bytes=208 
2015-06-27T17:37:49.558547+00:00 app[web.1]: Visitor detected. 
2015-06-27T17:37:49.620318+00:00 app[web.1]: Visitor connected to the database. 
2015-06-27T17:37:49.753657+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1435426664135-2&sid=tpgz2B5g5izndmQ5AAAA" host=myappname.herokuapp.com request_id=13166a2f-9bf6-46bb-969d-a44b13725dc2 fwd="67.188.41.245" dyno=web.1 connect=1ms service=3ms status=200 bytes=244 
2015-06-27T17:37:49.959264+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=1435426664231-3&sid=tpgz2B5g5izndmQ5AAAA" host=myappname.herokuapp.com request_id=765cfa24-32bb-43d2-92fb-d6311f8426f4 fwd="67.188.41.245" dyno=web.1 connect=1ms service=107ms status=200 bytes=207 
2015-06-27T17:37:50.210001+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=myappname.herokuapp.com request_id=8fabea41-f27d-430e-b7d1-f8592688fe98 fwd="67.188.41.245" dyno=web.1 connect=1ms service=2ms status=200 bytes=1222 
2015-06-27T17:37:59.634566+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket&sid=tpgz2B5g5izndmQ5AAAA" host=myappname.herokuapp.com request_id=1eaa4ed9-af78-4d11-8188-1727f07020f3 fwd="67.188.41.245" dyno=web.1 connect=1ms service=9884ms status=101 bytes=129 
2015-06-27T17:37:59.608947+00:00 app[web.1]: 
2015-06-27T17:37:59.609077+00:00 app[web.1]: /app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:796 
2015-06-27T17:37:59.609349+00:00 app[web.1]:  catch(err) { process.nextTick(function() { throw err}); } 
2015-06-27T17:37:59.609626+00:00 app[web.1]:              ^
2015-06-27T17:37:59.612942+00:00 app[web.1]: TypeError: Object function (object) { 
2015-06-27T17:37:59.612945+00:00 app[web.1]:  for(var key in object) { 
2015-06-27T17:37:59.612947+00:00 app[web.1]:  this[key] = object[key]; 
2015-06-27T17:37:59.612948+00:00 app[web.1]:  } 
2015-06-27T17:37:59.612950+00:00 app[web.1]:  return this; 
2015-06-27T17:37:59.612952+00:00 app[web.1]: } has no method 'ha' 
2015-06-27T17:37:59.612953+00:00 app[web.1]:  at /app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:991:52 
2015-06-27T17:37:59.612957+00:00 app[web.1]:  at Callbacks.emit (/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3) 
2015-06-27T17:37:59.612955+00:00 app[web.1]:  at /app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:795:13 
2015-06-27T17:37:59.612958+00:00 app[web.1]:  at null.messageHandler (/app/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23) 
2015-06-27T17:37:59.612960+00:00 app[web.1]:  at Socket.<anonymous> (/app/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:259:22) 
2015-06-27T17:37:59.612961+00:00 app[web.1]:  at Socket.emit (events.js:95:17) 
2015-06-27T17:37:59.612963+00:00 app[web.1]:  at Socket.<anonymous> (_stream_readable.js:765:14) 
2015-06-27T17:37:59.612964+00:00 app[web.1]:  at Socket.emit (events.js:92:17) 
2015-06-27T17:37:59.612965+00:00 app[web.1]:  at emitReadable_ (_stream_readable.js:427:10) 
2015-06-27T17:37:59.612967+00:00 app[web.1]:  at emitReadable (_stream_readable.js:423:5) 
2015-06-27T17:37:59.635022+00:00 app[web.1]: 
2015-06-27T17:37:59.647397+00:00 app[web.1]: npm ERR! Additional logging details can be found in: 
2015-06-27T17:37:59.647506+00:00 app[web.1]: npm ERR!  /app/npm-debug.log 
2015-06-27T17:37:59.647691+00:00 app[web.1]: npm ERR! not ok code 0 
2015-06-27T17:37:59.641575+00:00 app[web.1]: npm ERR! [email protected] start: `node server` 
2015-06-27T17:37:59.641769+00:00 app[web.1]: npm ERR! Exit status 8 
2015-06-27T17:37:59.642010+00:00 app[web.1]: npm ERR! 
2015-06-27T17:37:59.642144+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script. 
2015-06-27T17:37:59.642697+00:00 app[web.1]: npm ERR! This is most likely a problem with the myappname package, 
2015-06-27T17:37:59.642829+00:00 app[web.1]: npm ERR! not with npm itself. 
2015-06-27T17:37:59.643634+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system: 
2015-06-27T17:37:59.643787+00:00 app[web.1]: npm ERR!  node server 
2015-06-27T17:37:59.643925+00:00 app[web.1]: npm ERR! You can get their info via: 
2015-06-27T17:37:59.644152+00:00 app[web.1]: npm ERR! There is likely additional logging output above. 
2015-06-27T17:37:59.644037+00:00 app[web.1]: npm ERR!  npm owner ls myappname 
2015-06-27T17:37:59.644298+00:00 app[web.1]: npm ERR! System Linux 3.13.0-49-generic 
2015-06-27T17:37:59.644444+00:00 app[web.1]: npm ERR! command "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start" 
2015-06-27T17:37:59.644576+00:00 app[web.1]: npm ERR! cwd /app 
2015-06-27T17:37:59.644985+00:00 app[web.1]: npm ERR! code ELIFECYCLE 
2015-06-27T17:37:59.644839+00:00 app[web.1]: npm ERR! npm -v 1.4.28 
2015-06-27T17:37:59.644716+00:00 app[web.1]: npm ERR! node -v v0.10.39 
2015-06-27T17:37:59.647150+00:00 app[web.1]: npm ERR! 
2015-06-27T17:38:00.515560+00:00 heroku[web.1]: Process exited with status 1 
2015-06-27T17:38:00.528546+00:00 heroku[web.1]: State changed from up to crashed 
+0

'TypeError'部分跟着那个'extend'源代码是很奇怪的...我真的不知道日志是怎么告诉我的。 – Benny

+0

您是否在部署之前收缩包装应用程序?它看起来像一个模块依赖问题给我。 https://docs.npmjs.com/cli/shrinkwrap – jared

+0

@jared我使用vm作为'vm.runInThisContext()'。该应用在没有MongoLab的Heroku上运行良好,并且可以在本地使用MongoDB。当我开始在Heroku上使用MongoLab时,它似乎只是一个问题。我仍然可以使用Heroku上的MongoLab连接到数据库,甚至可以记录我加载的数据,但在用户连接后它仍然会崩溃几秒钟。本地,它从不崩溃,用户可以做的东西。 – Benny

回答

0

问题是,我有一个公用文件,设置不同的原语的prototype方法。看来我的一个npm也在prototype上设置属性,导致一些简单的命名冲突。

我创建了一个实用程序包装器(类似于underscore.js),它现在可以工作。