Closed
Description
Currently, when compiling in WASM mode, the dart.library.js
environment constant is set to true. This constant is used in particular in multi-platform applications to determine when the compilation target is a JS environment and as such various JS-interop libraries, such as dart:js
, dart:js_util
, and the js
package are safe to load. However, this is not true in a WASM environment, causing numerous build failures (which are particularly difficult to debug because they don't include traces indicating the import chain that caused them).
Here's a minimal reproduction:
import 'dart:core'
if (dart.library.js) 'dart:js';
void main() {
print('hello, world!');
}
When compiled with dart compile wasm test.dart
, this produces
*NOTE*: Compilation to WasmGC is experimental.
The support may change, or be removed, with no advance notice.
test.dart:1:1: Error: JS interop library 'dart:js' can't be imported when compiling to Wasm.
Try using 'dart:js_interop' or 'dart:js_interop_unsafe' instead.
import 'dart:core'
^