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

What support do we have for webpack and other bundlers?

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Native
    • Labels:
      None

      This commit attempted to use feature detection to dynamically import in features only supported in Node 10+. This was perfectly safe for users running the driver unmodified in a node environment >=4, as the file itself was not imported. However, it wound up breaking a few cases:

      • In some cases, babel would disrupt the feature detection by polyfilling Symbol.asyncIterator (see NODE-1908.) Was fixed in this commit.
      • Some users were applying webpack to their server-side code. Because they were bundling code at compile time, they were automatically including the disruptive code, causing applications to break. We were able to come up with workarounds for this issue (see NODE-1908 and NODE-1922), and the issue was fixed in this commit.
      • The now.sh platform automatically bundles code when deployed server side, meaning users could not employ the workarounds they normally would for bundling issues. See NODE-1908, zeit/now-cli#2053, and zeit/now-builders#335. This issue will also be resolved by this commit.

      While we have fixed all the broken builds, we still have to deal with the issue of users attempting to use webpack and other bundlers on the driver. Some points to consider:

      • We do link to some binary modules like kerberos, which AFAIK will not work out of the box with webpack.
      • There are some things that are perfectly valid node syntax (like dynamically requiring in files, and using variables in `require` calls) but will not work in bundlers.
      • Bundlers are not necessary for node. There is a decent chance that a user does not intend to bundle mongodb into their project. It can inflate the bundle by hundreds of kB with no appreciable gain.
      • Supporting webpack may implicitly encourage users to attempt to run the driver in a web browser (which either will not work or become a major security issue)
      • Certain projects like now.sh attempt to bundle code without the users knowing, leading to situations where code works fine in a dev environment, but fails in production.

      This raises the following questions:

      • Do we intend to support webpack and other bundlers
      • How do we document this?
      • Is there anything we can do on our end to ensure that these types of bugs do not show up?
      • Tests we can run
      • Documentation
      • Changes to package.json that will help compatibility with bundlers?

            Assignee:
            Unassigned Unassigned
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: