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.
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'))\")"]
Ran this command npm install -g node-gyp
I've updated the mongoose version to 3.8.21 inside package.json
Nothing works. Please suggest
This question is related to
javascript
angularjs
windows
node.js
mongodb
I'm working with OS Windows 8.1 and I had the same problem. The source of the problem was the version of Python. I found the origin problem review the file ...\node_modules\mongodb\node_modules\mongodb-core\node_modules\kerberos\builderror.log.
I installed the correct version of Python (2.7.9 for 64 bits) and it resolved my problem.
Note: The installed version of python must be equal or greater than 2.7.5 and less than 3.0.0
In our case, the reason that the c++ version bson was not found was because we were behind a corporate proxy and something in the BSON build process needs to reach out to fetch files. When we looked in node_modules/bson/builderror.log, we saw an error like this:
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: connect ECONNREFUSED
gyp ERR! stack at errnoException (net.js:904:11)
gyp ERR! stack at Object.afterConnect [as oncomplete] (net.js:895:19)
Which suggested that the proxy might be the issue. Setting the http_proxy and https_proxy environment variables solved it.
Sorry for reawakening comments on this, but I wanted to post this for anyone else that hits this in the future since this thread was very helpful in solving our issue.
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.
If you are using windows 8.1, you might want to make sure that you are installing your npm modules with the correct visual studio compiler.
I have Visual Studio 2012 installed, this command works for me. (after deleting node_modules dir)
npm install --msvs_version=2012
For some reason, node-gyp is trying to use the incorrect version of Visual Studio compiler. I also noticed that the "npm install" command was printing out a warnings about not node-gyp dependencies when installing the mongodb and mongoose modules.
After using the correct msvs_version, the npm install warnings went away as well as the console warning when running my nodejs app.
You might also want to make sure that you have the correct Python 2.7.X version installed and not Python 3.0.X.
You will also need to make sure that python is in your env path.
I also have this problem.
But I change my mongodb version to "^2.2.33" and no longer have the problem.
You shoud npm rm
your old mongodb package on global or local and install this version.
If anyone don't want to have any side-effect on changing the direction name could try this method.
Tried npm install mongoose --msvs_version=2012, if you have multiple Visual installed, it worked for me
I solved this error by doing this and it perfectly worked for me. I have created a node App which has the folder node-android/node-modules.So here inside the node-modules directory I have one more directory bson/ext/index.js open this file and you can find inside the catch block.
bson = require('../build/Release/bson');
change the above line to
bson = require('../browser_build/bson');
and the error was gone for me and the app is running perfectly without any errors or warnings.
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!
Unfortunately, All the above answers are only half right.. Took a long time to figure this out..
Mongoose bson install via npm throws warning and causes the error...
npm install -g node-gyp
git clone https://github.com/mongodb/js-bson.git
cd js-bson
npm install
node-gyp rebuild
This works like magic!!
So, i have the same problem and it happens then the specified mongoDB URL doesn't exist. So, to fix this you need to go "..\server\config\environment" folder and edit in "development.js" file the link to mongoDB.
Example:
// Development specific configuration
// ==================================
module.exports = {
// MongoDB connection options
mongo: {
uri: 'mongodb://localhost/test2-dev'
},
seedDB: true
};
So, change this "uri: 'mongodb://localhost/test2-dev'" to some real path to your mongoDB database.
I will be glad if my post will help somebody...
For today (year 2017) we have that awesome npm module: https://github.com/felixrieseberg/windows-build-tools which usually solves lots of troubles with building of native things for windows.
Try to fix the issue with:
Remove node_modules
npm install --global windows-build-tools
npm install
You should never change files in NODE_MODULES library folder.
Those files are result of npm install
command.
Basicaly, I think for Windows users - right way is use VM. It's what I'm doing when I work from home.
All you need:
for CentOS: yum install gcc gcc-c++ make openssl-devel
for Debian/Ubuntu: apt-get install build-essential
and then npm install
or, if you have already done it - npm update
First copy bson.js
code from browser_build folder
second create new file bson.js
and paste code
third save the new file near to in index.js
.
The best solution for me was to upgrade from node-mongodb 1.x to 2.x.
When I was getting errors like this, I was upgrading from node v0.10 to node v4.x.x . What I had to do was install a newer version of gcc (I think I had gcc v4.4.x or something). I updated to gcc 4.7.2 and things worked after that.
Deploying Keystone JS CMS I had same error and I think most elegant solution is this:
Install npm-check-updates
:
root@keystonejs:~# npm install -g npm-check-updates
Within your keystone site directory, where package.json
is placed, check dependencies:
debian@keystonejs:~/myproject/manalcjim$ npm-check-updates -u
Then update all packages:
debian@keystonejs:~/myproject/manalcjim$ npm install
And finally if you chose jade
for templates, maybe you will need install jade
module explicitly:
debian@keystonejs:~/myproject/manalcjim$ npm install jade --save
While creating setup for www.spotdekho.com
in new windows10
machine, I was unable to run command "nodemon web.js"
due same error
"Error: Cannot find module '../build/Release/bson'"
Got it fixed by below steps :
- Create folder "Release" inside "node_modules\bson\build\" location
- Copy bson.js from "node_modules\bson\browser_build\"
- Paste bson.js inside "node_modules\bson\build\Release" folder.
This will resolve the issue.
PS : I am using mongoose version 4.8.8 .
Thanks :) , hope it helps someone .
Run this command to uninstall mongoose npm uninstall --save mongoose
- thereafter reinstall it but this time npm
automatically installs the latest version of mongoose run npm install --save mongoose
This worked for me.
Install the latest version of mongodb.
Make sure your package.json is using the latest version of mongodb, then remove node_modules/mongodb and do npm install again. If you didn't use mongodb as a direct dependency, try to find which package is using mongdb. I used:
find . -type f -name package.json | xargs grep mongodb
...
./sails-mongo/package.json: "mongodb": "1.4.26",
...
So I updated ./sails-mongo/package.json to:
"mongodb": "2.1.7",
Then remove node_modules/mongodb and do npm install again. Seems fine now.
I don't like the current suggested way of using
require('../browser_build/bson')
Since looking at ../browser_build/bson.js, a 4k+ lines file, which seem also a "non-native" implementation. So although it won't spit out any complains, it is still "using pure JS version", which means slower performance.
Looking at https://github.com/mongodb/js-bson/issues/145 and https://github.com/mongodb/js-bson/issues/165, it seems like the issue was caused by:
antoniofruci commented on Sep 15, 2015
I just found out that c++ code has been moved out 6 months ago and it is now an optional dependency: bson-ext. Indeed, if you install latest version no error occurs.
So I tried to remove the whole node_modules and still got the same error. And looking at package.json of node_modules/mongodb, its version is still 1.4.26, not latest 2.1.7.
Apparently my mongodb comes as a dependency of another package I installed: sails-mongo. Modifying the package.json of sails-mongo and redoing npm install finally solve the issue.
find in npm module mongodb ..node_modules\mongodb\node_modules\bson\ext\index.js
and change path to js version in catch block
bson = require('../build/Release/bson');
to bson = require('../browser_build/bson');
try {
// Load the precompiled win32 binary
if(process.platform == "win32" && process.arch == "x64") {
bson = require('./win32/x64/bson');
} else if(process.platform == "win32" && process.arch == "ia32") {
bson = require('./win32/ia32/bson');
} else {
bson = require('../browser_build/bson');
}
} catch(err) {
// Attempt to load the release bson version
try {
bson = require('../browser_build/bson');
} catch (err) {
console.dir(err)
console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
bson = require('../lib/bson/bson');
}
}
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
I also had the same problem with bson.
trying a newer mongoose version
npm install [email protected]
solved the issue.
Massimo.
I tried this in mongo-sync version 4.1.2
but they made some changes and it is not working with the solutions provided here
the solution which worked for me
Path node_modules/mongo-sync/node_modules/bson/ext/index.js
Old Code
try {
// Load the precompiled win32 binary
if (process.platform == "win32" && process.arch == "x64") {
bson = require('./win32/x64/bson');
} else if (process.platform == "win32" && process.arch == "ia32") {
bson = require('./win32/ia32/bson');
} else {
bson = require('../build/Release/bson');
}
} catch (err) {
// Attempt to load the release bson version
try {
bson = require('../build/Release/bson');
} catch (err) {
console.dir(err)
console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
bson = require('../lib/bson/bson');
}
}
Change in the try block (copy the bson initialization from catch block)
bson = require('../lib/bson/bson');
So it will look like
try {
// Load the precompiled win32 binary
if(process.platform == "win32" && process.arch == "x64") {
bson = require('./win32/x64/bson');
} else if(process.platform == "win32" && process.arch == "ia32") {
bson = require('./win32/ia32/bson');
} else {
bson = require('../build/Release/bson');
}
} catch(err) {
// Attempt to load the release bson version
try {
bson = require('../lib/bson/bson');
} catch (err) {
console.dir(err)
console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
bson = require('../lib/bson/bson');
}
}
I had the same issue after upgrade version of ubuntu to 16.04. I solved in this way, hope it helps.
$rm -rf node_modules
$npm --save install bson
$npm --save install mongoose
$npm install
I realize this thread is 1 year + old, but it helped me, albeit with a different module.
I installed mongoose-post-findv0.0.2 and this issue started. To fix it, I used the suggestions and navigated to \node_modules\mongoose-post-find\node_modules\bson\ext and opened the index.js file.
The file starts off with a try catch block trying to require the correct bson version
try {
// Load the precompiled win32 binary
if(process.platform == "win32" && process.arch == "x64") {
bson = require('./win32/x64/bson');
} else if(process.platform == "win32" && process.arch == "ia32") {
bson = require('./win32/ia32/bson');
} else {
bson = require('../build/Release/bson');
}
} catch(err) {
// Attempt to load the release bson version
try {
bson = require('../browser_build/bson');
} catch (err) {
console.dir(err)
console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
bson = require('../lib/bson/bson');
}
}
this is the corrected version. What was happening is it tried to load bson from ../build/Release/bson, couldn't find it and fell into the catch. There is tried to load bson again from ../build/Release/bson and of course failed. So I changes the path in the catch to look in ../browser_build/bson. This resolved the error.
I post this for completeness.
Try npm install [email protected]
and also replace
bson = require('../build/Release/bson');
to
bson = require('../browser_build/bson');
in node_modules/bson/ext/index.js
I've tried bson = require('../browser_build/bson');
but end up running into another error
Cannot set property 'BSON_BINARY_SUBTYPE_DEFAULT' of undefined
Finally I fixed this issue simply by npm update
, this will fix the bson module in mongoose.
Try this npm install bson
and npm update
I resolved this issue by installing mogoose version 3.8.23
npm install [email protected]
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!
The only thing which helps me on Windows 7 (x64): https://stackoverflow.com/a/29714359/2670121
Reinstall node and python with x32 versions.
I spent many time with this error (Failed to load c++ bson extension) and finally, when I installed module node-gyp
(for build native addons) and even installed windows SDK with visual studio - nodejs didn't recognize assembled module bson.node as module. After reinstall the problem is gone.
Again, What means this error?
Actually, it's even not error. You still can use mongoose. But in this case, instead of fast native realization of bson module, you got js-realization, which slower. I saw many tips like: "edit path deep inside node_modules..." - which totaly useless because it's not solve the problem but just turned off the error messages.
The marked answer is completely wrong. All that does is hide the console log statement and does nothing whatsoever do address the actually issue. You can also close your eyes and it will achieve the same result.
The issue is caused by node-gyp and only that. Its purpose is to compile native extensions for certain modules such as bson.
If it fails to do so then the code will fallback to the JS version and kindly tell you so through the informative message:
Failed to load c++ bson extension, using pure JS version
I assume the question is really about how to compile the native C++ extension rather that just not seeing the message so let's address that.
In order for node-gyp to work your node-gyp must be up to date with your node and C++ compiler (that will differ based on your OS). Just as important your module must also be up to date.
First uninstall and reinstall node-gyp
npm un node-gyp -g;npm i node-gyp -g
Now you will need to fully uninstall and reinstall any node module in your app (that includes modules installed by requirements as well) that have bson. That should take care of the error. You can search for 'Release/bson' and find the culprits.
find node_modules/ -type 'f' -exec grep -H 'Release/bson' {} \;
And then uninstall and reinstall these modules.
Easier is to just redo the entire node_modules
folder:
rm -rf node_modules
npm cache clear
npm i
If you still experience issues then either 1) your module is out of date - check issue tracker in their repo or 2) you have a potential conflict - sometimes we may have a local node-gyp for example. You can run node-gyp
by itself and verify versions.
In my case, the bits that come with mongoose (npm install mongoose
) have a working version of the mongodb
package in its node_modules
folder.
The following steps saved me the work of troubleshooting the issue:
npm install mongoose
node_modules\mongoose\node_modules\mongodb
to my root node_modules
folder (overwriting any version that came with npm install mongodb
)Failed to load c++ bson extension...
error (or change the code to be silent on the issue)This worked for me:
Go to the file (in your project):
node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
and change:
bson = require('../build/Release/bson');
to:
bson = require('bson');
For everyone still searching for a solution, I solved it by
bson = require('../../../browser_build/bson.js');
instead of
bson = require(../browser_build/bson.js');
so look if the path is correct.
First I just find in npm module mongodb the file index.js ..node_modules\mongodb\node_modules\bson\ext\index.js
and change path to js version in catch block
bson = require('../build/Release/bson'); to bson = require('../browser_build/bson');
but then I just changed it like this, all the similar... previously installed the module... : bson = require('bson');
Source: Stackoverflow.com