2015-06-27 136 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),它現在可以工作。