Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when bundling code in version 3.3.1 #98

Open
ValYouW opened this issue Jul 14, 2024 · 6 comments
Open

Error when bundling code in version 3.3.1 #98

ValYouW opened this issue Jul 14, 2024 · 6 comments

Comments

@ValYouW
Copy link

ValYouW commented Jul 14, 2024

After upgrading to version 3.3.1 I started to get the following error when building my code (using esbuild):

The top-level await in "node_modules/bson/lib/bson.mjs" is here:

    node_modules/bson/lib/bson.mjs:111:26:
      111 │ const nodejsRandomBytes = await (async () => {
          ╵                           ~~~~~

It seems the error comes from bson lib that was updated in version 3.3.1 to ^5.4.0 (used to be 4.5.2 in 3.2.1)

@mongo-J
Copy link
Collaborator

mongo-J commented Jul 14, 2024

Hi @ValYouW, thank you for raising this issue and sorry for the inconvenience. For esbuild, have you tried to alias the bson to use cjs as below. I've done a quick test in my local environment it seems to resolve this issue. You should also be able to define this from an esconfig file. We had a similar issue during our testing in which we've added an alias to the package.json which fixed this problem for a few other bundling tools, but looks like esbuild doesn't not pick up this from package.json. We are also trying to workout with the bson library team to if there can be a better solution to this.

--alias:bson="./node_modules/bson/lib/bson.cjs"

@jyriaganitsh
Copy link

I had similar issue. I downgraded back to v.3.0.0 and seems it helped to resolve the issue for now.

@peters
Copy link

peters commented Jul 29, 2024

Same here. Had to downgrade to v3.2.1.

1 similar comment
@troyha
Copy link

troyha commented Aug 7, 2024

Same here. Had to downgrade to v3.2.1.

@Anton-Plagemann
Copy link

Got the same issue with nuxt (vite) :(
Had to use https://github.com/Menci/vite-plugin-top-level-await to make it work.
Any chance for a fix?

@dgwight
Copy link

dgwight commented Sep 6, 2024

To use version 3.3.1 of mongodb-js/charts-embed-sdk, set the overrides or resolves of bson in the package.json to force it to use that version

For npm

  "overrides": {
    "bson": "^4.5.2"
  }

For yarn

  "resolves": {
    "bson": "^4.5.2"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants