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

Property await does not exist in the latest version of React Native (v0.79.1), error thrown in node_modules/bson/lib/bson.mjs

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

      In the latest version of React Native (v0.79.1), using await directly is not allowed in certain places, which results in the following error

       

      PATH: node_modules/bson/lib/bson.mjs
      // Throw the error: property 'await' does not exist

       

      The error occurs when attempting to use await directly for dynamic imports in the node_modules/bson/lib/bson.mjs file:

      const nodejsRandomBytes = await (async () => {
          try {
              return (await import('crypto')).randomBytes;
          }
          catch {
              return nodejsMathRandomBytes;
          }
      })();

       

      Steps to Reproduce:

      1. Use React Native version 0.79.1
      1. Attempt to run the app with a dependency on the bson package and import them
      1. Observe the error message in the logs: "property 'await' does not exist".

      Steps to Resolved 

      Replace that section with:
      const nodejsRandomBytes = (async () => {
      try {
      constcrypto=awaitimport('crypto');
      returncrypto.randomBytes;
      }
      catch {
      returnnodejsMathRandomBytes;
      }
      })();

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            quaid.ahmed@ripeseed.io Quaid Ahmed
            None
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: