跳到主要内容
CNode

io.js下MongoDB驱动的问题

问答
WWangZishi发布于 11 年前最后回复 11 年前
555260

操作系统: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 [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm WARN package.json [email protected] license should be a valid SPDX license expression
 
> [email protected] 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

> [email protected] 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
[email protected] node_modules/consolidate

[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/mongodb
├── [email protected]
└── [email protected]

看起来安装应该没有问题 但是执行$ iojs app.js的时候控制台输出:

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

为啥bson组建加载失败呢?install的时候也没有warning或者error。 求指教

查看回复

回复 (5)

J
jackhutu#511 年前

楼上正解。

H
haozxuan#411 年前

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

W
WangZishi#211 年前

找到原因了,是我的mongodb的版本老了 把package.json里面的"mongodb": "~1.3.10"改成"mongodb": "^2.0.33" 然后执行 $ npm update 控制台输出

> [email protected] 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 [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany npmlog was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany request was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany semver was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany tar was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany tar-pack was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany mkdirp was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany rc was bundled with [email protected], but bundled package wasn't found in unpacked tree
npm WARN installMany rimraf was bundled with [email protected], but bundled package wasn't found in unpacked tree
\
> [email protected] 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
[email protected] node_modules/mongodb
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])

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

L
leapon#111 年前

这个和 io.js 没关系,在 nodejs 下也会出现。应该是你的build环境缺东西。 http://stackoverflow.com/questions/21656420/failed-to-load-c-bson-extension

参与回复

登录后即可参与回复。登录