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

Cant use BSON ObjectId in browser

    • Type: Icon: Question Question
    • Resolution: Community Answered
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.0
    • Component/s: BSON
    • Labels:
    • 1
    • 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?

      What problem are you facing?

      When importing ObjectId from bson browser throws "Uncaught ReferenceError: await is not defined" at nodejsRandomBytes

      What driver and relevant dependency versions are you using?

      mongo 5.0

      node v16.20.2

      Steps to reproduce?

      Create a web app project with parcel or vite

      Install the mongo 5.0 as a dependency

      Import ObjectId from bson and use it on the client side

      The browser will throw an error from nodejsRandomBytes

      Uncaught ReferenceError: await is not defined
          at 2hiev.c2053a55dbc6d0ad (node_byte_utils.ts:49:1)
          at newRequire (index.0641b553.js:71:24)
          at localRequire (index.0641b553.js:84:35)
          at bNKaB.bson (app.js:1:1)
          at newRequire (index.0641b553.js:71:24)
          at index.0641b553.js:122:5
          at index.0641b553.js:145:3

       

       

      Repo to reproduce the issue mateo-morales-garcia-gamecoderstudios/bson-not-working-parcel: testing object id from bson not working in parcel (github.com)

       

      Also managed to reproduce it with vite here https://stackblitz.com/edit/vitejs-vite-hwav3o?file=src%2Fcounter.ts

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            mateo.morales@gamecoderstudios.com Mateo Morales García
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: