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 ([key]Ctrl + Alt + T[/key]) 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 ([key]Alt + F12 [/key] ) , 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

[ebs_well type=”well-sm”]
** Depending on your set up you may need to run these commands with super user account privileges i.e. sudo
[/ebs_well]

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.

Recommended reading
[ebs_row] [ebs_column lg=”4″ md=”12″ sm=”12″ xs=”12″ ] [amazon template=iframe image&asin=1449344682] [/ebs_column] [ebs_column lg=”4″ md=”12″ sm=”12″ xs=”12″ ] [amazon template=iframe image&asin=1491949309] [/ebs_column] [ebs_column lg=”4″ md=”12″ sm=”12″ xs=”12″ ] [amazon template=iframe image&asin=1782168192] [/ebs_column] [/ebs_row] [ebs_well type=”well-lg”]
If you have any further questions please ask in the comments section below or contact me and I will endeavour to respond as soon as I can.
[/ebs_well]

Gary Woodfine

Technical Director at Denizon
Gary is Technical Director at Denizon, an independent software vendor specialising in IoT, Field Service and associated managed services,enabling customers to be efficient, productive, secure and scalable in a way which helps them address and reduce their ecological impact.

Denizon's product line successfully integrate IoT, Artificial Intelligence and Blockchain technology to enable efficient, productive, secure and scalable solutions to help organisations address increasing energy demands, ecological impact and Health & Safety concerns of their staff.

Latest posts by Gary Woodfine (see all)