[Node.js] Let's use stable version to avoid MONGOOSE WARNING

Tadashi Shigeoka ·  Tue, June 30, 2015

If you get a MONGOOSE WARNING message when developing Node.js + Mongoose apps, you’re likely using an unstable version, so let’s use a stable version.

mongoose | マングース

First, when trying to start the app, you get angrily warned with !!! MONGOOSE WARNING !!!

$ node-dev app.js     

##############################################################
#
#   !!! MONGOOSE WARNING !!!
#
#   This is an UNSTABLE release of Mongoose.
#   Unstable releases are available for preview/testing only.
#   DO NOT run this in production.
#
##############################################################

Error: Cannot find module 'knox'
    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. (/Users/username/works/myapp/routes/admin/content.js:5:12)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.nodeDevHook [as .js] (/Users/username/.nvm/v0.10.28/lib/node_modules/node-dev/lib/hook.js:43:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
[ERROR] 10:45:21 Error

package.json had “mongoose”: “^3.8.13”, written, so after npm install, Mongoose version 3.9.7 was installed.

$ npm list | grep mongoose
├─┬ [email protected] invalid
├─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
├── [email protected]
npm ERR! invalid: [email protected] /Users/username/myapp/node_modules/mongoose
npm ERR! not ok code 0

Check the Mongoose version and rewrite package.json to a usable stable version, then run npm install again and it should be OK.

$ git diff

diff --git a/package.json b/package.json
index e56cf62..6b49881 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
-    "mongoose": "^3.8.13",
+    "mongoose": "3.8.13",

The following site provides detailed information about how to write package.json, so it might be good to read it as well.

Reference Information

That’s all from the Gemba.