Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM incorrectly advertises dart.library.js #55801

Closed
nex3 opened this issue May 21, 2024 · 2 comments
Closed

WASM incorrectly advertises dart.library.js #55801

nex3 opened this issue May 21, 2024 · 2 comments
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-js-interop Issues that impact all js interop

Comments

@nex3
Copy link
Member

nex3 commented May 21, 2024

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'
^
@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-dart2wasm Issues for the dart2wasm compiler. labels May 21, 2024
@mkustermann
Copy link
Member

/cc @srujzs

@srujzs srujzs added web-js-interop Issues that impact all js interop area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels May 22, 2024
@srujzs
Copy link
Contributor

srujzs commented May 22, 2024

Duplicate of #55266

Prefer dart.library.html to differentiate between a JS compiler and dart2wasm for now.

This was added to support some allowInterop stuff early on, but is no longer needed, so should indeed be removed. I believe you'll see the same behavior when doing conditional imports with dart.library.js_util, but that might require some internal migration first before I can remove it from libraries.json.

@srujzs srujzs marked this as a duplicate of #55266 May 22, 2024
@kevmoo kevmoo closed this as completed May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart2wasm Issues for the dart2wasm compiler. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

5 participants