无法加载c ++ bson扩展这里有一个总节点noob。我一直在尝试设置一个示例节点应用程序但每次尝试运行时都会弹出以下错误:节点应用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)
3 回答
不负相思意
TA贡献1777条经验 获得超10个赞
通过添加此行尝试捕获块路径,轻松解决问题: node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
bson = require('bson'); instead bson = require('./win32/ia32/bson');bson = require('../build/Release/bson');
就这些!!!
守候你守候我
TA贡献1802条经验 获得超10个赞
在WIN 8.1上
好像我在package.json文件中使用了错误版本的mongoose。
我从package.json中删除了行“mongoose”:“^ 3.8.15”
CLI:npm install mongoose --save
现在它在package.json中说“mongoose”:“^ 4.0.6”,我的错误消失了。
万千封印
TA贡献1891条经验 获得超3个赞
Followint @ user1548357我决定更改模块文件本身。为了避免下面有效评论指出的问题,我在postinstall脚本中包含了我的更改,以便我可以设置并忘记它,并确保它将在我的模块安装时运行。
// package.json"scripts": { // other scripts "postinstall": "node ./bson.fix.js"},
并且脚本是:
// bson.fix.jsvar fs = require('fs');var file = './node_modules/bson/ext/index.js'fs.readFile(file, 'utf8', function (err,data) { if (err) { return console.log(err); } var result = data.replace(/\.\.\/build\/Release\/bson/g, 'bson'); fs.writeFile(file, result, 'utf8', function (err) { if (err) return console.log(err); console.log('Fixed bson module so as to use JS version'); });});
添加回答
举报
0/150
提交
取消