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

js-bson - PR #643: fix: use Symbol.for('id') in ObjectId to fix errors when mixing cjs and mjs

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • bson-6.4.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • 0
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      dot-i has created PR #643: fix: use Symbol.for('id') in ObjectId to fix errors when mixing cjs and mjs in js-bson

      Fix interoperability of bson between ESM and CommonJS.

      What is changing?

      Symbol('id') is replaced with Symbol.for('id') in objectid.ts. This avoids the issue of two different symbols being used for ESM and CommonJS, causing ObjectId.equals() to fail with an undefined error.

      Is there new documentation needed for these changes?

      No.

      What is the motivation for this change?

      We are switching our modules to be ESM and ran in to this issue because we imported bson directly from our module (ESM), but also sometimes through a CommonJS import which in turn also imported bson – but as CommonJS module.

      This caused ObjectId.equals() to fail since there were two separate 'id' symbols in use, causing an undefined error.

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            dbeng-pm-bot PM Bot
            Durran Jordan, Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: