io.js下MongoDB驱动的问题
发布于 10 年前 作者 WangZishi 5306 次预览 最后一次回复是 10 年前 来自 问答
操作系统:Mac OS X 环境:xcode command line tools、io.js 2.2.1、npm 2.11.0
app.js
var express = require('express'),
cons = require('consolidate'),
mongodb = require('mongodb');
package.json
{
"name":"intro_npm",
"version":"0.0.0",
"description": "npm introduction",
"main": "app.js",
"dependencies": {
"consolidate": "~0.9.1",
"express": "~3.2.6",
"mongodb": "~1.3.10"
},
"author": "Shaun Verch",
"license": "BSD"
}
bash 执行npm install的结果
npm WARN package.json intro_npm@0.0.0 No repository field.
npm WARN package.json intro_npm@0.0.0 No README data
npm WARN package.json intro_npm@0.0.0 license should be a valid SPDX license expression
> kerberos@0.0.3 install /Users/wangzishi/Test/intro_npm/node_modules/mongodb/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/kerberos/lib/kerberos.o
> bson@0.2.5 install /Users/wangzishi/Test/intro_npm/node_modules/mongodb/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bson/ext/bson.o
consolidate@0.9.1 node_modules/consolidate
express@3.2.6 node_modules/express
├── methods@0.0.1
├── fresh@0.1.0
├── range-parser@0.0.4
├── cookie-signature@1.0.1
├── buffer-crc32@0.2.1
├── cookie@0.1.0
├── commander@0.6.1
├── mkdirp@0.3.4
├── debug@2.2.0 (ms@0.7.1)
├── send@0.1.0 (mime@1.2.6)
└── connect@2.7.11 (pause@0.0.1, bytes@0.2.0, qs@0.6.5, cookie@0.0.5, send@0.1.1, formidable@1.0.14)
mongodb@1.3.23 node_modules/mongodb
├── kerberos@0.0.3
└── bson@0.2.5
看起来安装应该没有问题 但是执行$ iojs app.js的时候控制台输出:
Failed to load c++ bson extension, using pure JS version
为啥bson组建加载失败呢?install的时候也没有warning或者error。 求指教
5 回复
这个和 io.js 没关系,在 nodejs 下也会出现。应该是你的build环境缺东西。 http://stackoverflow.com/questions/21656420/failed-to-load-c-bson-extension
找到原因了,是我的mongodb的版本老了 把package.json里面的
"mongodb": "~1.3.10"改成"mongodb": "^2.0.33"然后执行$ npm update控制台输出虽然看起来好多坑爹的警告,不过貌似不再会提示bson加载失败了。
@leapon 也许吧,但总感觉那些WARN可能和io.js有关
node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/index.js 看下有惊喜。
楼上正解。