How should I load JS libraries from within WASM? #55806
Labels
area-dart2wasm
Issues for the dart2wasm compiler.
area-web-js
Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
web-js-interop
Issues that impact all js interop
(Potentially related to #55733)
Currently, it's unclear what the "well-paved road" is for loading JavaScript libraries within a WASM context. For built-in JS APIs, it's easy: I use
dart:js_interop
to define the shape of the JS API I want to use and tell Dart what its global name is, and then it gets wired up for me in the generatedmjs
wrapper. But what if I want to access a name that's not globally available in every context?Any global name I write via
dart:js_interop
gets translated in themjs
wrapper toglobalThis.<name>
. But adding values to this isn't very ergonomic; for example, you can't write:myapp.mjs
won't seeglobalThis.lib
. You'd have to put that assignment in a third library in order for it to work. Is that really the expected pattern here? Or should there be a better way?The text was updated successfully, but these errors were encountered: