Skip to content

WASM incorrectly advertises dart.library.js #55801

Closed
@nex3

Description

@nex3

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'
^

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-js-interopIssues that impact all js interop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions