mongoose: js-bson: Failed to load c++ bson extension, using pure JS version

I clicked on Fork, cloned the repo and I attached this module to my project. I get this error

js-bson: Failed to load c++ bson extension, using pure JS version

nodejs v0.11.13, latest osx. It looks that the problem is with the mongodb module (works with bson 0.2.15).

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 117 (3 by maintainers)

Most upvoted comments

When using with Keystone this is what worked for me to get past that error:

add the following to my package.json deps:

"mongoose": "~4.4.16",
"mongodb": "~2.1.18",
"keystone": "^0.3.19",

then

npm install

finally

rm -rf node_modules/keystone/node_modules/mongodb
rm -rf node_modules/keystone/node_modules/mongoose

Now I don’t get the error.

@mgol I use OSX 10.10.5, node 4.4.2, npm 2.15.0, keystone 0.3.17

I went to node_modules/keystone/package.json, and remove mongoose from dependencies, then

npm config set python python2.7
npm install mongoose

this worked for me:

I just resolved that.

When you install the mongoose module by npm, it does not have a built bson module in it’s folder. In the file node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js, change the line

bson = require(‘…/build/Release/bson’); to

bson = require(‘bson’);

I update my mongoose package to 3.9.7 the problem fixed but I got this message from mongoose:

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

@GST5555 if you would like to get some help in real time, please feel free to join us in either of these communities: Gitter.im Slack

@mnpenner Yes,you are a smart man!

How is this still an issue??? Should I even bother leaving any further information here… everyone else has done that for me… Is anyone going tostabilize this or what???

rm -rf node_modules && npm cache clean && npm install doesn’t works for me, after same error

Mongoose only requires Python inasmuch as node-gyp (node wrapper around v8 build system) requires python. Python is not a runtime dependency for mongoose. If you need documentation that mongoose needs python in order to build the C++ bson parser, click here.

However, once again, mongoose will work as expected even if it can’t build the bson parser. The only feature that requires node-gyp to succeed is the kerberos authentication mechanism.

Using

npm config set python python2.7
cd node_modules/mongoose/node_modules/mongodb/node_modules/bson
npm install

worked for me!

You win!

Please excuse me, it was my fault.

builderror.log: gyp ERR! configure error gyp ERR! stack Error: Python executable “python” is v3.4.2, which is not supported by gyp. gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0. gyp ERR! stack at failPythonVersion (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:108:14) gyp ERR! stack at /usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:97:9 gyp ERR! stack at ChildProcess.exithandler (child_process.js:735:7) gyp ERR! stack at ChildProcess.emit (events.js:110:17) gyp ERR! stack at maybeClose (child_process.js:1008:16) gyp ERR! stack at Socket.<anonymous> (child_process.js:1176:11) gyp ERR! stack at Socket.emit (events.js:107:17) gyp ERR! stack at Pipe.close (net.js:476:12) gyp ERR! System Linux 3.14.27-1-lts gyp ERR! command “node” “/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild” gyp ERR! cwd /home/node/sites/hellooo/src/node_modules/mongoose/node_modules/mongodb/node_modules/bson gyp ERR! node -v v0.12.0 gyp ERR! node-gyp -v v1.0.2 gyp ERR! not ok

In my case the solution was:

npm config set python python2.7

Reinstall mongoose and working.

I did not pay attention to this lines from the output of ‘npm install’:

bson@0.2.19 install /home/node/sites/hellooo/src/node_modules/mongoose/node_modules/mongodb/node_modules/bson (node-gyp rebuild 2> builderror.log) || (exit 0)

This means there was an error when building bson I had not noticed.

Thank you very much @vkarpov15.

“Fixing” this in general isn’t really possible, because this error message can mean one of numerous things. It can mean that you don’t have a proper version of python or a proper C++ compiler installed (because of node-gyp), it can mean that you switched versions of node from when you npm installed mongoose, etc.