【问题标题】:Failed to load c++ bson extension, using pure JS version when using monk to access Mongodbc++ bson扩展加载失败,使用mongodb访问mongodb时使用纯js版本
【发布时间】:2015-01-24 06:18:25
【问题描述】:

当我想使用monk作为中间件访问mongodb时,提示

使用纯JS版本加载c++ bson扩展失败

我正在运行的 evn 如下:

  1. OS X 优胜美地
  2. 节点 v0.10.32
  3. npm 1.4.28
  4. MongoDB 2.6.5
  5. 和尚 0.9.1 有谁知道如何解决这个问题?

【问题讨论】:

标签: javascript node.js mongodb monk


【解决方案1】:

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

去和尚 index.js 文件 (yourProjectDirectory/node_modules/monk/node_modules/mongodb/node_modules/bson/ext/index.js)

应该是这样的

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

将catch块改为

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

希望对你有帮助

大卫

【讨论】:

    猜你喜欢
    • 2015-03-06
    • 2015-08-09
    • 2015-04-23
    • 2014-06-05
    • 2015-08-27
    • 2015-08-30
    • 2015-09-23
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多