angular/angular-cli

Cannot be used with BSON library

XhstormR opened this issue · 3 comments

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I want to integrate the bson library into the app, library repo https://github.com/mongodb/js-bson, but an error occurred during build.

I have searched those pages, it shows I can switch builder to @angular-devkit/build-angular:browser-esbuild to fix this error, but now it doesn't work.

#26507
https://stackoverflow.com/questions/77287205/error-upon-importing-bson-library-saying-the-top-level-await-experiment-is-not

Minimal Reproduction

in the angular project folder and run:

bun add bson
bun run build

Exception or Error

=> bun run  build
$ ng build 
Application bundle generation failed. [8.210 seconds]

✘ [ERROR] Top-level await is not available in the configured target environment ("chrome120.0", "edge120.0", "firefox115.0", "ios16.0", "safari16.0" + 5 overrides)

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


error: script "build" exited with code 1

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 17.3.0
Node: 22.0.0 (Unsupported)
Package Manager: bun 1.1.5
OS: darwin x64

Angular: 17.3.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.0
@angular-devkit/build-angular   17.3.0
@angular-devkit/core            17.3.0
@angular-devkit/schematics      17.3.0
@schematics/angular             17.3.0
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.4

Warning: The current version of Node (22.0.0) is not supported by Angular.

Anything else relevant?

No response

Duplicate of #26507

Top level awaits are not supported and explicitly disabled as these can use a certain optimisations not to work correctly.

@alan-agius4 is there a way to make bson library work with angular?

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.