2

using mongodb3.0, node 0.12.0, npm 2.5.1 on windows 7 integrale, I am trying to read and write data into my database, but i have this error in npm intsall!

{ [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

i tried to replace

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

into

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

but i had errors like this:

 exports.BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0 TypeError: Cannot set property       'BSON_BINARY_SUBTYPE_DEFAULT' of undefined  

i am using monk, anfd i have run npm mongodb, npm monk

ch hach
  • 17
  • 1
  • 6
  • Does the code run anyway with the first error? I've received that error too, but it hasn't affected the code. – Kevin B Mar 24 '15 at 17:37
  • sure it doesn't affect rest of your code but it is really unpleasant. In my case everything used to work until i run npm update – Marcel Djaman May 28 '15 at 00:21

4 Answers4

6

Problem: Modules like Mongo-DB, Socket.io and other requires node-gyp to compile C/C++ code which Kim also discussed. MSVC++ comes only for 32-bit OS, NOW this is the real problem because if you've install node.js and the other requirments like Python 2.7.3 with the 64-bit versions, then you'll face the problems like I did.

Follow these steps:

  • Uninstall Node.js
  • Uninstall all the Modules including Python
  • Now Install 32-bit versions of all the above uninstalled applications and platforms.
  • Follow all the necessary steps.
  • Now install modules you want to use.

You may see some errors while installing, but don't panic. Try running your application and it will work just fine.

NOTE: This solution is platform specific i.e. for MS Windows.

halfer
  • 19,824
  • 17
  • 99
  • 186
aitchkhan
  • 1,842
  • 1
  • 18
  • 38
  • This is the only thing that helps me. I spent about 4h with dancing around this problem. Finaly, the problem was with the node (0.12.3 x64) which didn't recognize bson.node as a module. When I reinstall all this stuff (node, python) with x32 versions, the problem is gone. – Maksim Nesterenko May 19 '15 at 03:24
  • I had this problem for 2 days. And after a lot of research I found this solution here on stackoverflow. But it was not explained in detail. So I chose to post this answer. Good luck. (y) – aitchkhan May 19 '15 at 04:38
  • i suspect the lastest version of node coz everything did work well until i run npm update in my x64 node – Marcel Djaman May 28 '15 at 00:23
  • @MarcelDjaman were you using Modules like mongoDB, socket.io with x64 node and were they working fine?? – aitchkhan May 28 '15 at 06:05
  • everything works fine expect some little nasty warning messages like js-bon failed to load c++ bson extension... – Marcel Djaman May 28 '15 at 11:15
  • I have the same warning messages but neither my modules like mongo or socket.io were working nor was my application until I followed those steps! – aitchkhan May 29 '15 at 06:31
1

I'm on windows 8.1, but what I did, was first install python 2.7.9 and also visual studio community edition. Both are needed to compile bson. Then I installed: "npm install -g node-gyp", after that I just deleted the node_modules from my project and did "npm install" again. Solved. When I did the install again I could see the message on the console that said bson was compiling.

jpablok
  • 11
  • 1
0

MongoDB depends on a few libraries. At some point you would have done:

npm install mongodb --save

One of these dependencies is node-gyp which is needed to compile bson. Importantly, node-gyp requires Python 2.7 and Microsoft Visual Studio to be installed (see installation section of node-gyp). If you don't have Python 2.7 and Visual Studio, then node-gyp will fail to build which means it can't compile bson (causing the initial error).

Navigate to: node_modules\mongodb\node_modules\mongodb-core\node_modules\bson

You should find the builderror.log file with more information about why node-gyp failed to build. Most likely this will be due to Python 2.7 or Visual Studio not being installed.

Here's what I had to do to fix it:

I had the exact same problem as you with the bson module not found error. I also changed the require line as you did and ended up with the same error (exports.BSON...). I then uninstalled monk and mongodb:

npm uninstall mongodb --save
npm uninstall monk --save

Installed Python 2.7 and Microsoft Visual Studio, then installed mongodb and monk again:

npm install mongodb --save
npm install monk --save

This fixed it.

  • I find bson in the same pathin the directory mongoose, is that ok? – ch hach Mar 25 '15 at 10:58
  • It stills have the same error! I tried to run node-gyp rebuild but i have this error : `gyp: binding.gyp not found (cwd: C:\Node\test) while trying to load binding.gyp gyp ERR! configure error gyp ERR! stack Error: `gyp` failed with exit code: 1 ` – ch hach Mar 25 '15 at 13:05
0

The problem is fixed when i changed the version of node 10.34 and nom 1.4.28

ch hach
  • 17
  • 1
  • 6