Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error upon importing BSON library saying "The top-level-await experiment is not enabled"

I get a top-level-await error upon when importing BSON:

./node_modules/bson/lib/bson.mjs - Error: Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-angular/src/tools/babel/webpack-loader.js
 * ./node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
Error: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)

Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)

I’m importing the library inside my component like so:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { ObjectId } from 'bson';

Been searching everywhere but can’t find an answer.

>Solution :

You can update your angular builder to esbuild:

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser-esbuild",

Still experimental in Angular, it’ll be tagged as stable with the Angular 17 release.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading