npm install mongoose fails (kerberos and bson errors)

21,188

Solution 1

After I cd'd into the kerberos and bson directories, I used the command $ node-gyp rebuild and the node modules compiled correctly.

My app.js file, I called the following lines:

var app = express();
...
var Mongoose = require('mongoose');
var db = Mongoose.createConnection('localhost','database');

// all environments
app.set('port', process.env.PORT || 3000);

This port number must be unique from the port of your database instance.

In a separate terminal window, run $ mongod to spool up your MongoDB. Once it's called, in yet another terminal window, you call $ mongo database. This creates the database instance called database for your Node.js app to connect to. In your original terminal window, call $ node app.js and it will run without any error feedback.

The errors I was getting were not the result of an incorrect build of Mongoose, MongoDB or any of their dependencies. The errors were a result of a misconception about MongoDB. MongoDB must be running as a process separate to your Node.js app in order for the app to make a database connection.

Solution 2

For anyone on a Linux distro ensure you have libkrb5-dev (or your distro's similar package) installed. This will take care of many build errors with bson and kerberos.

Solution 3

For ubuntu users, first uninstall moongose

npm uninstall mongoose --save

then install the a kerberos update

apt-get install libkrb5-dev

then "install" moongose again

npm install mongoose --save

I hope this helps somebody there.

Solution 4

I've fixed this by installing node-gyp into the global scope. Hope it helps.

$ npm install -g node-gyp 

Solution 5

I just uninstall mongodb and then install mongoose successfully.

npm uninstall mongodb --save
npm install mongoose --save
Share:
21,188
Caleb Faruki
Author by

Caleb Faruki

Updated on July 30, 2022

Comments

  • Caleb Faruki
    Caleb Faruki over 1 year

    So I'm attempting to launch my node app, but there's a few errors arising from my MongoDB installation.

    Here are the specs for my dev environment:

    node => 0.10.33 (installed from nodejs.org)

    npm => 1.4.28 (installed from nodejs.org)

    git => 2.1.3 (homebrewed)

    mongodb => 2.6.5 (homebrewed)

    If it makes a difference, I am also using the Mean Stack Skeleton as part of a tutorial.

    In a nutshell, when I try to run my node app using $ node app.js, I get the following feedback:

    USER$ npm install mongoose
    
    > [email protected] install /Users/USER/APP/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos
    > (node-gyp rebuild 2> builderror.log) || (exit 0)
    
      CXX(target) Release/obj.target/kerberos/lib/kerberos.o
      CXX(target) Release/obj.target/kerberos/lib/worker.o
      CC(target) Release/obj.target/kerberos/lib/kerberosgss.o
      CC(target) Release/obj.target/kerberos/lib/base64.o
      CXX(target) Release/obj.target/kerberos/lib/kerberos_context.o
      SOLINK_MODULE(target) Release/kerberos.node
      SOLINK_MODULE(target) Release/kerberos.node: Finished
    
    > [email protected] install /Users/USER/APP/node_modules/mongoose/node_modules/mongodb/node_modules/bson
    > (node-gyp rebuild 2> builderror.log) || (exit 0)
    
      CXX(target) Release/obj.target/bson/ext/bson.o
      SOLINK_MODULE(target) Release/bson.node
      SOLINK_MODULE(target) Release/bson.node: Finished
    [email protected] node_modules/mongoose
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected]
    ├── [email protected] ([email protected])
    └── [email protected] ([email protected], [email protected], [email protected])
    

    I checked the builderror.log files for both the kerberos and bson modules. However, both are empty.

    Some research I have found suggests that the issue might be because my node-gyp installation does not have a corresponding binding.gyp file.

    Also tried running $ node-gyp configure inside my Node.js project folder. And this is the error I received:

    gyp: binding.gyp not found (cwd: /Users/USER/APP) while trying to load binding.gyp
    gyp ERR! configure error
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:343:16)
    gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:810:12)
    gyp ERR! System Darwin 12.5.0
    gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure"
    gyp ERR! cwd /Users/USER/APP
    gyp ERR! node -v v0.10.33
    gyp ERR! node-gyp -v v1.0.2
    gyp ERR! not ok
    

    Any ideas why I am having these issues?

    EDIT: After setting the port in my app.js file to set the port to the same one that the Express server is listening on (duh), I get more feedback indicating that I was using Mongoose 3.9.4, which is the latest unstable release of mongoose. So I set the module to 3.8.18 in my package.json and attempted to reinstall the module. I received the same errors. However, the unstable release feedback is gone now.