Javascript 找不到模块 '../build/Release/bson'] 代码:'MODULE_NOT_FOUND' } js-bson:无法加载 c++ bson 扩展,使用纯 JS 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28651028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version
提问by navra
I am getting the below error:
我收到以下错误:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
Here are my version details:
这是我的版本详细信息:
OS: Windows 7
MongoDB: 2.6.5
Node: 0.12.0
操作系统:Windows 7
MongoDB:2.6.5
节点:0.12.0
I have tried these things before I posted the issue here.
在我在这里发布问题之前,我已经尝试过这些事情。
I went to
\node-modules\mongoose\node-modules\mongodb\node-modules\bsonfolder and made below change in the binding-gyp file from'include_dirs': [ '<!(node -e "require(\'nan\')")' ]to'include_dirs': ["<!(nodejs -p -e \"require('path').dirname(require.resolve('nan'))\")"]Ran this command
npm install -g node-gypI've updated the mongoose version to 3.8.21 inside
package.json
我去了
\node-modules\mongoose\node-modules\mongodb\node-modules\bson文件夹,并从绑定GYP文件下的变化做出'include_dirs': [ '<!(node -e "require(\'nan\')")' ]对'include_dirs': ["<!(nodejs -p -e \"require('path').dirname(require.resolve('nan'))\")"]运行这个命令
npm install -g node-gyp我已经将 mongoose 版本更新到了 3.8.21 里面
package.json
Nothing works. Please suggest
什么都行不通。请建议
回答by anydasa
Find in npm module mongodb:
在 npm 模块 mongodb 中找到:
..\node_modules\mongodb\node_modules\bson\ext\index.js
..\node_modules\mongodb\node_modules\bson\ext\index.js
Change path to js version in catch block:
在 catch 块中更改 js 版本的路径:
bson = require('../build/Release/bson');
To:
到:
bson = require('../browser_build/bson');
Or copy file in:
或将文件复制到:
..\node_modules\bson\build\Release\bson
..\node_modules\bson\build\Release\bson
From:
从:
..\node_modules\bson\browser_build\bson
..\node_modules\bson\browser_build\bson
回答by Matt West
I had this issue today (Feb 19th, 2016) and I solved it just by installing the latest version of Mongoose. Try putting this in your package.json:
我今天(2016 年 2 月 19 日)遇到了这个问题,我只是通过安装最新版本的 Mongoose 解决了这个问题。试着把它放在你的 package.json 中:
"mongoose": "~4.4"
Hope that helps. Solved it for me!
希望有帮助。帮我解决了!
回答by salihcenap
The problem is when you install mongoose via npm it assumes you have python installed on your windows and tries to build required libraries. Since you do not have python it skips building phase with a warning. But when you start your application, required modules are not there so you get this error.
问题是当您通过 npm 安装 mongoose 时,它假定您的 Windows 上安装了 python 并尝试构建所需的库。由于您没有 python,它会跳过构建阶段并发出警告。但是当您启动应用程序时,所需的模块不存在,因此您会收到此错误。
In order to do things right first install python (version 2.7) on your computer from: https://www.python.org/downloads/or if u have installed chockolatey just type choco install python2.
为了正确地做事,首先从以下位置在您的计算机上安装 python(2.7 版):https: //www.python.org/downloads/ 或者如果您已经安装了 chockolatey 只需键入choco install python2.
Then make sure your python variable is set. You can set it on command prompt like:
然后确保您的python变量已设置。您可以在命令提示符下设置它,例如:
SET python=D:\Python27\python.exe
(Of course you should change the path according to your location of python) Then install node-gyp:
(当然你要根据你python所在的位置改变路径)然后安装node-gyp:
npm install -g node-gyp
Now you can reinstall mongoose or whatever module causing the problem:
现在您可以重新安装猫鼬或导致问题的任何模块:
npm install mongoose
You will see some yellow lines instead of red ones this time but the error will be gone.
这次您会看到一些黄线而不是红线,但错误将消失。
回答by Rishabh Garg
I resolved this issue by installing mogoose version 3.8.23
我通过安装 mogoose 版本解决了这个问题 3.8.23
npm install [email protected]
回答by kahlal
This worked for me. Search in your workspace for the text:
这对我有用。在您的工作区中搜索文本:
"../build/Release/bson"
You will probably find it inside the mongose and monk modules.
您可能会在猫鼬和僧侣模块中找到它。
Then replace each:
然后替换每个:
bson = require('../build/Release/bson');
with:
和:
bson = require('bson');
that's all!
就这样!
回答by Peter
Short answer
简答
Install the latest version of mongodb.
安装最新版本的 mongodb。
A little longer answer
回答有点长
Make sure your package.json is using the latest version of mongodb, then remove node_modules/mongodb and do npm install again. If you didn't use mongodb as a direct dependency, try to find which package is using mongdb. I used:
确保您的 package.json 使用的是最新版本的 mongodb,然后删除 node_modules/mongodb 并再次执行 npm install。如果您没有使用 mongodb 作为直接依赖项,请尝试查找使用 mongdb 的包。我用了:
find . -type f -name package.json | xargs grep mongodb
...
./sails-mongo/package.json: "mongodb": "1.4.26",
...
So I updated ./sails-mongo/package.json to:
所以我将 ./sails-mongo/package.json 更新为:
"mongodb": "2.1.7",
Then remove node_modules/mongodb and do npm install again. Seems fine now.
然后删除 node_modules/mongodb 并再次执行 npm install。现在好像还好。
Even longer answer
更长的答案
I don't like the current suggested way of using
我不喜欢当前建议的使用方式
require('../browser_build/bson')
Since looking at ../browser_build/bson.js, a 4k+ lines file, which seem also a "non-native" implementation. So although it won't spit out any complains, it is still "using pure JS version", which means slower performance.
由于查看 ../browser_build/bson.js,一个 4k+ 行的文件,这似乎也是一个“非本地”实现。所以虽然它不会吐出任何抱怨,但它仍然是“使用纯JS版本”,这意味着性能更慢。
Looking at https://github.com/mongodb/js-bson/issues/145and https://github.com/mongodb/js-bson/issues/165, it seems like the issue was caused by:
查看https://github.com/mongodb/js-bson/issues/145和 https://github.com/mongodb/js-bson/issues/165,问题似乎是由以下原因引起的:
antoniofruci commented on Sep 15, 2015
I just found out that c++ code has been moved out 6 months ago and it is now an optional dependency: bson-ext. Indeed, if you install latest version no error occurs.
antoniofruci 于 2015 年 9 月 15 日发表评论
我刚刚发现 C++ 代码已在 6 个月前移出,现在它是一个可选的依赖项:bson-ext。实际上,如果您安装最新版本,则不会发生错误。
So I tried to remove the whole node_modules and still got the same error. And looking at package.json of node_modules/mongodb, its version is still 1.4.26, not latest 2.1.7.
所以我试图删除整个 node_modules 并且仍然遇到相同的错误。再看node_modules/mongodb的package.json,它的版本还是1.4.26,不是最新的2.1.7。
Apparently my mongodb comes as a dependency of another package I installed: sails-mongo. Modifying the package.json of sails-mongo and redoing npm install finally solve the issue.
显然,我的 mongodb 是我安装的另一个包的依赖项:sails-mongo。修改sails-mongo的package.json,重做npm install终于解决了。
回答by Raghav Manikandan
Try npm install [email protected]and also replace
bson = require('../build/Release/bson');to
尝试npm install [email protected]并替换
bson = require('../build/Release/bson');为
bson = require('../browser_build/bson');in node_modules/bson/ext/index.js
bson = require('../browser_build/bson');在 node_modules/bson/ext/index.js
回答by Franco
This worked for me:
这对我有用:
Go to the file (in your project):
转到文件(在您的项目中):
node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
node_modules/mongoose/node_modules/mongodb/node_modules/bson/ext/index.js
and change:
并改变:
bson = require('../build/Release/bson');
bson = require('../build/Release/bson');
to:
到:
bson = require('bson');
bson = require('bson');
回答by Manuel Alcocer
Deploying Keystone JS CMSI had same error and I think most elegant solution is this:
部署Keystone JS CMS我有同样的错误,我认为最优雅的解决方案是这样的:
Install npm-check-updates:
安装npm-check-updates:
root@keystonejs:~# npm install -g npm-check-updates
Within your keystone site directory, where package.jsonis placed, check dependencies:
在您package.json放置的keystone 站点目录中,检查依赖项:
debian@keystonejs:~/myproject/manalcjim$ npm-check-updates -u
Then update all packages:
然后更新所有包:
debian@keystonejs:~/myproject/manalcjim$ npm install
And finally if you chose jadefor templates, maybe you will need install jademodule explicitly:
最后,如果您选择jade模板,也许您需要jade明确安装模块:
debian@keystonejs:~/myproject/manalcjim$ npm install jade --save
回答by Spotdekho
While creating setup for www.spotdekho.comin new windows10machine, I was unable to run command "nodemon web.js"due same error
www.spotdekho.com在新windows10机器上创建设置时,"nodemon web.js"由于同样的错误,我无法运行命令
"Error: Cannot find module '../build/Release/bson'"
“错误:找不到模块'../build/Release/bson'”
Got it fixed by below steps :
通过以下步骤修复它:
- Create folder "Release" inside "node_modules\bson\build\" location
- Copy bson.js from "node_modules\bson\browser_build\"
- Paste bson.js inside "node_modules\bson\build\Release" folder.
- 在“node_modules\bson\build\”位置创建文件夹“Release”
- 从“node_modules\bson\browser_build\”复制bson.js
- 将 bson.js 粘贴到“node_modules\bson\build\Release”文件夹中。
This will resolve the issue.
这将解决问题。
PS : I am using mongoose version 4.8.8 .
PS:我使用的是猫鼬版本 4.8.8。
Thanks :) , hope it helps someone .
谢谢:),希望它可以帮助某人。

