Failed to load c++ bson extension, using pure JS version when using monk to access Mongodb

1k Views Asked by At

When I want to use monk as a middleware to access the mongodb, it prompts that

Failed to load c++ bson extension, using pure JS version

My running evn is the following:

  1. OS X Yosemite
  2. Node v0.10.32
  3. npm 1.4.28
  4. Mongodb 2.6.5
  5. monk 0.9.1 Does any of you know how to fix the issue?
1

There are 1 best solutions below

0
On

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

Go the the monk index.js file (yourProjectDirectory/node_modules/monk/node_modules/mongodb/node_modules/bson/ext/index.js)

It should 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('../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 the catch block to

try {
...
} 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');
    }
}

Hope this helps

David