无法加载 c++ bson 扩展

这里的总节点菜鸟。我一直在尝试设置示例节点应用程序,但每次尝试运行时都会弹出以下错误:

节点应用

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

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: failed to connect to [#$%67890 :27017]
    at null.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:553:74)
    at EventEmitter.emit (events.js:106:17)
    at null.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
    at EventEmitter.emit (events.js:98:17)
    at Socket.<anonymous> (/home/thejazeto/code/nodejs/authen/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:830:16
    at process._tickCallback (node.js:415:13)

答案 1

我猜你在安装mongodb库时没有可用的工具。我建议你做

xcode-select --install(在 Mac 上)或 (在 ubuntu 上)sudo apt-get install gcc make build-essential

并运行

rm -rf node_modules
npm cache clean
npm install

或者只是根据@tobias注释进行npm更新(安装构建基本版后)

npm update

答案 2

我刚刚解决了这个问题。

当您通过npm安装猫鼬模块时,它的文件夹中没有构建的bson模块。在文件中,更改行node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js

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

bson = require('bson');

然后使用 npm 安装 bson 模块。