io.js下MongoDB驱动的问题
发布于 9 年前 作者 WangZishi 4894 次浏览 最后一次编辑是 8 年前 来自 问答

操作系统: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 控制台输出

> kerberos@0.0.12 install /Users/wangzishi/Test/intro_npm/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/kerberos/lib/kerberos.o
  CXX(target) Release/obj.target/kerberos/lib/worker.o
  CC(target) Release/obj.target/kerberos/lib/kerberosgss.o
  CC(target) Release/obj.target/kerberos/lib/base64.o
  CXX(target) Release/obj.target/kerberos/lib/kerberos_context.o
  SOLINK_MODULE(target) Release/kerberos.node
  SOLINK_MODULE(target) Release/kerberos.node: Finished
npm WARN installMany nopt was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany npmlog was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany request was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany semver was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany tar was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany tar-pack was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany mkdirp was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany rc was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
npm WARN installMany rimraf was bundled with node-pre-gyp@0.6.4, but bundled package wasn't found in unpacked tree
\
> bson-ext@0.1.7 install /Users/wangzishi/Test/intro_npm/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext
> (node-pre-gyp install --fallback-to-build) || (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/bson/ext/bson.o
../ext/bson.cc:825:17: warning: 'DecodeBytes' is deprecated: Use DecodeBytes(isolate, ...) [-Wdeprecated-declarations]
                ssize_t len = DecodeBytes(args[0], BINARY);
                              ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:318:32: note: 'DecodeBytes' has been explicitly marked deprecated here
                inline ssize_t DecodeBytes(
                               ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:66:42: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                                         ^
../ext/bson.cc:833:3: warning: 'DecodeWrite' is deprecated: Use DecodeWrite(isolate, ...) [-Wdeprecated-declarations]
                DecodeWrite(data, len, args[0], BINARY);
                ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:331:32: note: 'DecodeWrite' has been explicitly marked deprecated here
                inline ssize_t DecodeWrite(char* buf,
                               ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:66:42: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                                         ^
../ext/bson.cc:928:28: warning: 'Encode' is deprecated: Use Encode(isolate, ...) [-Wdeprecated-declarations]
                Local<Value> bin_value = Encode(serialized_object, object_size, BINARY)->ToString();
                                         ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:299:45: note: 'Encode' has been explicitly marked deprecated here
                inline v8::Local<v8::Value> Encode(
                                            ^
/Users/wangzishi/.node-gyp/2.2.1/src/node.h:66:42: note: expanded from macro 'NODE_DEPRECATED'
    __attribute__((deprecated(message))) declarator
                                         ^
3 warnings generated.
  SOLINK_MODULE(target) Release/bson.node
  SOLINK_MODULE(target) Release/bson.node: Finished
mongodb@2.0.33 node_modules/mongodb
├── readable-stream@1.0.31 (isarray@0.0.1, inherits@2.0.1, string_decoder@0.10.31, core-util-is@1.0.1)
└── mongodb-core@1.1.32 (kerberos@0.0.12, bson@0.3.2)

虽然看起来好多坑爹的警告,不过貌似不再会提示bson加载失败了。

@leapon 也许吧,但总感觉那些WARN可能和io.js有关

node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext/index.js 看下有惊喜。

楼上正解。

回到顶部