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

Change to conditional imports broke web platform #3173

Closed
daniel-v opened this issue Aug 19, 2021 · 2 comments
Closed

Change to conditional imports broke web platform #3173

daniel-v opened this issue Aug 19, 2021 · 2 comments

Comments

@daniel-v
Copy link

@jakemac53 's changes in #3170 as a response to @mraleph 's issue of dart-lang/sdk#46918 has had some side effects.

Namely, I cannot build any of my projects that depend on conditional imports to differentiate between VM and web platforms.
A good example would be package:universal_html that is publicly available.

  • Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "linux_x64"
  • Affected builder package: build_modules v4.0.2 (v4.0.1 works fine)

Repro code

import 'package:universal_html/html.dart';

void main() {
  print(document.body != null);
}

Observed errors

With DDC:

# dart run build_runner serve web:8080
[SEVERE] build_modules:module_library on package:universal_html/js.dart: Invalid argument(s): Unsupported conditional import of `dart:js` found in universal_html|lib/js.dart:

export 'dart:js';

This environment does not support direct conditional imports of `dart:` libraries. Instead you must create a separate library which unconditionally imports (or exports) the `dart:` library that you want to use, and conditionally import (or export) that library.

With dart2js

# dart run build_runner serve -r --define 'build_web_compilers|entrypoint=compiler=dart2js' --define 'build_web_compilers|entrypoint=dart2js_args=["-O1"]' web:8080

[SEVERE] build_modules:module_library on package:universal_html/js.dart (cached):

Invalid argument(s): Unsupported conditional import of `dart:js` found in universal_html|lib/js.dart:

export 'dart:js';
@jakemac53
Copy link
Contributor

The example you have shown was never intended to work. I think there was a bug where we allowed conditional imports/exports of dart: libraries if the default import was a dart: library.

I would forward fix the package to export a library that exports dart:js.

@jakemac53
Copy link
Contributor

Note that if you attempted to compile for the vm (with build_vm_compilers) I am quite sure it would not have worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants