Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-698

Browserify compatibility

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.1.16
    • Component/s: BSON
    • Environment:
      OS X El Capitan 10.11.4
      npm 3.8.8
      node 4.4.3

      Hi,

      I'm trying to bundle a js file, which uses mongodb, using browserify but I'm not able to. I receive the error

      browserified.js:14223, BSON = require('bson').native().BSON

      TypeError: require(...).native is not a function

      The code is very simple

      var MongoClient = require('mongodb').MongoClient;
      var x = "Hello NodeJS";
      
      console.log(x);
      
      MongoClient.connect("mongodb://localhost:27017/test", (err, db) => {
        console.log("Error null? " + (err == null ? "YES" : "NO"));
        console.log("DB null? " + (db == null ? "YES" : "NO"));
      });
      

      and I'm bundling it up using

      bg. browserify simple.js -o browserified.js

      I'm trying to use it in NodeJS. Someone in Stack Overflow pointed me to this https://github.com/substack/node-browserify#compatibility saying browserify shims some node modules to also work on the browser, so I don't know if it might be the case it is causing some problems in your implementation in case the driver is using any of those

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            marcelocbf Marcelo Freitas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: