Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version

前端 未结 30 2222
予麋鹿
予麋鹿 2020-11-28 02:19

I am getting the below error:

{ [Error: Cannot find module \'../build/Release/bson\'] code: \'MODULE_NOT_FOUND\' } 
  js-bson: Failed to load c++ bson extens         


        
相关标签:
30条回答
  • 2020-11-28 02:33

    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:

    "mongoose": "~4.4"
    

    Hope that helps. Solved it for me!

    0 讨论(0)
  • 2020-11-28 02:34

    While creating setup for www.spotdekho.com in new windows10 machine, I was unable to run command "nodemon web.js" due same error

    "Error: Cannot find module '../build/Release/bson'"

    Got it fixed by below steps :

    1. Create folder "Release" inside "node_modules\bson\build\" location
    2. Copy bson.js from "node_modules\bson\browser_build\"
    3. Paste bson.js inside "node_modules\bson\build\Release" folder.

    This will resolve the issue.

    PS : I am using mongoose version 4.8.8 .

    Thanks :) , hope it helps someone .

    0 讨论(0)
  • 2020-11-28 02:34

    find in npm module mongodb ..node_modules\mongodb\node_modules\bson\ext\index.js

    and change path to js version in catch block

    bson = require('../build/Release/bson');
    

    to bson = require('../browser_build/bson');

    try {
            // Load the precompiled win32 binary
            if(process.platform == "win32" && process.arch == "x64") {
              bson = require('./win32/x64/bson');  
            } else if(process.platform == "win32" && process.arch == "ia32") {
              bson = require('./win32/ia32/bson');  
            } else {
             bson = require('../browser_build/bson');  
            }   
        } catch(err) {
            // Attempt to load the release bson version
            try {
                bson = require('../browser_build/bson');
            } catch (err) {
                console.dir(err)
                console.error("js-bson: Failed to load c++ bson extension, using pure JS version");
                bson = require('../lib/bson/bson');
            }
        }
    
    0 讨论(0)
  • 2020-11-28 02:37

    Short answer

    Install the latest version of 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:

    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:

    "mongodb": "2.1.7",
    

    Then remove node_modules/mongodb and do npm install again. Seems fine now.

    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.

    Looking at https://github.com/mongodb/js-bson/issues/145 and https://github.com/mongodb/js-bson/issues/165, it seems like the issue was caused by:

    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.

    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.

    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.

    0 讨论(0)
  • 2020-11-28 02:39

    Deploying Keystone JS CMS I had same error and I think most elegant solution is this:

    Install npm-check-updates:

    root@keystonejs:~# npm install -g npm-check-updates
    

    Within your keystone site directory, where package.json is placed, check dependencies:

    debian@keystonejs:~/myproject/manalcjim$ npm-check-updates -u
    

    Then update all packages:

    debian@keystonejs:~/myproject/manalcjim$ npm install
    

    And finally if you chose jade for templates, maybe you will need install jade module explicitly:

    debian@keystonejs:~/myproject/manalcjim$ npm install jade --save
    
    0 讨论(0)
  • 2020-11-28 02:40

    Try this npm install bson and npm update

    0 讨论(0)
提交回复
热议问题