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

140,924

Solution 1

Find in npm module mongodb:

..\node_modules\mongodb\node_modules\bson\ext\index.js

Change path to js version in catch block:

bson = require('../build/Release/bson');

To:

bson = require('../browser_build/bson');

Or copy file in:

..\node_modules\bson\build\Release\bson

From:

..\node_modules\bson\browser_build\bson

Solution 2

I had this issue today (Feb 19th, 2016) and I solved it just by installing the latest version of Mongoose. Try putting this in your package.json:

"mongoose": "~4.4"

Hope that helps. Solved it for me!

Solution 3

The problem is when you install mongoose via npm it assumes you have python installed on your windows and tries to build required libraries. Since you do not have python it skips building phase with a warning. But when you start your application, required modules are not there so you get this error.

In order to do things right first install python (version 2.7) on your computer from: https://www.python.org/downloads/ or if u have installed chockolatey just type choco install python2.

Then make sure your python variable is set. You can set it on command prompt like:

SET python=D:\Python27\python.exe

(Of course you should change the path according to your location of python) Then install node-gyp:

npm install -g node-gyp

Now you can reinstall mongoose or whatever module causing the problem:

npm install mongoose

You will see some yellow lines instead of red ones this time but the error will be gone.

Solution 4

I resolved this issue by installing mogoose version 3.8.23

npm install [email protected]

Solution 5

This worked for me. Search in your workspace for the text:

"../build/Release/bson"

You will probably find it inside the mongose and monk modules.

Then replace each:

bson = require('../build/Release/bson');

with:

bson = require('bson');

that's all!

Share:
140,924

Related videos on Youtube

navra
Author by

navra

Updated on March 09, 2020

Comments

  • navra
    navra about 4 years

    I am getting the below error:

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

    Here are my version details:

    • OS: Windows 7

    • MongoDB: 2.6.5

    • Node: 0.12.0

    I have tried these things before I posted the issue here.

    1. I went to \node-modules\mongoose\node-modules\mongodb\node-modules\bson folder and made below change in the binding-gyp file from 'include_dirs': [ '<!(node -e "require(\'nan\')")' ] to 'include_dirs': ["<!(nodejs -p -e \"require('path').dirname(require.resolve('nan'))\")"]

    2. Ran this command npm install -g node-gyp

    3. I've updated the mongoose version to 3.8.21 inside package.json

    Nothing works. Please suggest

    • navra
      navra about 9 years
      I have tried below options suggested by you but no avail. I am getting below error { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version c:\raj\project\meandemo\node_modules\express\lib\router\rout‌​e.js:170 throw new Error(msg); ^ Error: Route.get() requires callback functions but got a [object Undefined] at Route.<anonymous>
    • ashishkumar148
      ashishkumar148 about 9 years
    • aitchkhan
      aitchkhan about 9 years
      Please see this solution, hope it works! As C++ BSON extension is required for several other Modules too. Kindly note that, this solution is specific For Microsoft-OS Win-7 stackoverflow.com/a/29714359/4154706
    • totymedli
      totymedli almost 8 years
      Check the answers in this question too: Failed to load c++ bson extension
    • mido
      mido about 7 years
      Possible duplicate of Failed to load c++ bson extension
  • anydasa
    anydasa about 9 years
    I can not say for sure. Is likely to be working well. This is a bug file paths.
  • Manatax
    Manatax about 9 years
    Awesome! Local environment though, so nothing tragic should happen anyway.
  • robor
    robor about 9 years
    bson = require('../../../browser_build/bson.js');
  • Veysel Ozdemir
    Veysel Ozdemir about 9 years
    Thank you. I needed to make a tweak in my case though, i didn't have a browser_build folder in bson_ext folder : My problem was in "node_modules\mongodb\node_modules\mongodb-core\node_modules‌​\bson\node_modules\b‌​son-ext\ext\index.js‌​". I changed the lines to "bson = require('../browser_build/bson');" AND copied the browser_build directory from "node_modules\mongodb\node_modules\mongodb-core\node_modules‌​\bson" (2 folders up) to "node_modules\mongodb\node_modules\mongodb-core\node_modules‌​\bson\node_modules\b‌​son-ext"
  • Bob Aleena
    Bob Aleena almost 9 years
    This was helpful! I had this problem with a bson installation with mongojs
  • Maksim Nesterenko
    Maksim Nesterenko almost 9 years
    This is not a solution. With the same result you can just remove strings which prints error. This error appears because of native c++ plugin for bson not found and in this case js realization will be used anyway.
  • anydasa
    anydasa almost 9 years
    Yes, it is not native use. but this solution
  • phocks
    phocks almost 9 years
    This worked for me on Windows 8.1 with Visual Studio Community Edition 2013 using npm install --msvs_version=2012
  • Xianlin
    Xianlin almost 9 years
    it's a 32bit vs 64bit thing, the solution is to install 32bit NodeJs and Python on windows 7 64bit. see stackoverflow.com/questions/29238424/…
  • Victor Ferreira
    Victor Ferreira almost 9 years
    worked here. is this an older version? why did it work?
  • MatthieuLemoine
    MatthieuLemoine almost 9 years
    The python's version is important. node-gyp doesn't work with version > 3.0
  • orszaczky
    orszaczky almost 9 years
    This is not a full solution... I'm still getting the following error: MSBUILD : error MSB3428: Could not load the Visual C++ component "VCBuild.exe".
  • Vikram Shetty
    Vikram Shetty over 8 years
    Make sure the path to the bson.js is correct. For me bson = require('../browser_build/bson.js'); worked. Also check the version mongoose before going for the installation.
  • RichieRich
    RichieRich over 8 years
    @TheRebel It's assuming vs2010 toolchain. Add --msvs-version=2012 or 2013e depending on what you have installed. e.g. npm install mongoose --msvs-version=2012
  • RichieRich
    RichieRich over 8 years
    It's not 32/64 issue. I just installed with binary drivers using all 64 bit. See my comment below with @salihcenap reply.
  • Thronk
    Thronk over 8 years
    He says right in the question he is using Windows 7 - how does CentOS and Debian command help?
  • Victor Perov
    Victor Perov over 8 years
    Oh, really, my bad. I didn't see that tag
  • Mark Stosberg
    Mark Stosberg over 8 years
    How did you get this fix to persist? Did you check in your node_modules directory into source control?
  • albert Jegani
    albert Jegani over 8 years
    still its not working for me..i m using latest version in node and mogodb
  • Gaurav Lad
    Gaurav Lad about 8 years
    The error got changed to : TypeError: Cannot set property 'BSON_BINARY_SUBTYPE_DEFAULT' of undefined
  • jsbisht
    jsbisht about 8 years
    what to do if i am deploying node app on heroku cloud.
  • totymedli
    totymedli almost 8 years
    @Alendorff True, but that is what most of us look for. I don't care about the C++ plugin, I want to get rid of the warnings because they break Node Inspector. From this perspective, your suggestion (removing error prints) is also a solution, because this shouldn't be an error, the code works fine with the JS fallback.
  • Edward Newell
    Edward Newell almost 8 years
    Worked for me. I think its all a problem with an old mongoose version, which I had from following an old tutorial. IMO this should be the correct answer.
  • bicycle
    bicycle almost 8 years
    Best answer, all the other ones about editing code within modules are hacks not solutions
  • RaneWrites
    RaneWrites about 7 years
    I was getting this error trying to run the default tests after setting up a project using meanjs. This fixed it. Thanks.
  • jrista
    jrista almost 7 years
    Sorry, downvoting as the second best answer here actually has the right, non-hack solution: Install a non-broken version of the package!
  • mikeym
    mikeym almost 7 years
    Most straight forward solution without the need to mess with node_modules/mongodb etc. Thanks!
  • MechaCode
    MechaCode about 6 years
    Replacing bson = require('../build/Release/bson'); to bson = require('../browser_build/bson'); worked for me.
  • Grijan
    Grijan about 6 years
    One of the best, just uninstall mongoose(npm uninstall mongoose) and reinstall it again(npm install mongoose)
  • Carl
    Carl over 5 years
    Changing package codes under node_modules seems like a bad practice
  • Felipe
    Felipe over 5 years
    yeah ... but it was necessary, in my case... perhaps that was a bug... nothing is perfect .... and that makes it much more fun