Skip to content

Remove Failed to load c++ bson extension message from MEAN.js application start

I have previously posted a How To:  install mean.js on ubuntu, In this post I will provide additional instructions on how to remove the error messages that may be displayed  when using Grunt to run your applications.

Once you have successfully completed the installation instructions contained in my previous posts  it may be possible you see error messages similar to the ones below:

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version

This error is generally results from when installing the Mongoose Module via the Node Package Manager (npm) it does not build the BSON module in the folder.  We will need to do this ourselves manually.

Build Essentials Linux

Open terminal window and navigate to your project directory, or if you're like me an you use Webstorm - The smartest JavaScript IDE you can open a terminal window with , and execute the following line

sudo apt-get install build-essential

Once that is complete, ensure you are in the root of project folder and execute the following lines;

rm -rf node_modules
npm cache clean
npm install

Essentially we will delete the node_modules folder in the project root, clean the cache and then re-create the folder and modules with the correct references.

This will clear up error messages and you should now be able to continue without the nagging doubt that something is wrong with your application.

Build Essentials Windows

Since I published this post, I have noticed a number of visits from users on windows based machines and a comment from a windows user asking about a windows solution.

I must confess to the fact that I have not done any node & mongodb development using windows, and therefore I cannot attest that the following solution will work.  The following solution is entirely based on advice provided by Christian Kvalheim's blog post , Diagnosing driver installation problems

Open visual studio command prompt. Ensure node.exe is in your path and install node-gyp.

npm install -g node-gyp

Next you will have to build the project manually to test it. Use any tool you use with git and grab the repo.

git clone https://github.com/mongodb/js-bson.git
cd js-bson
npm install
node-gyp rebuild

Calvin is currently working on a fix to completely remove this conflict but due to some considerable technical challenges this may take some time.

Latest posts by Gary Woodfine (see all)