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

[build_web_compilers] Crashes due to wrongly analyzed libraries. #3666

Closed
schultek opened this issue Apr 5, 2024 · 4 comments · Fixed by #3667
Closed

[build_web_compilers] Crashes due to wrongly analyzed libraries. #3666

schultek opened this issue Apr 5, 2024 · 4 comments · Fixed by #3667

Comments

@schultek
Copy link

schultek commented Apr 5, 2024

I came across a super weird bug that causes this error:

[WARNING] build_web_compilers:entrypoint on web/main.dart:
Skipping compiling myapp|web/main.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:

myapp|lib/main.dart

https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings

Which is wrong since the file in question definitely does not import any unsupported libraries. It is caused by some other file in the package that imports some unsupported libs, but that is not anywhere in the transitive imports of the entrypoint file.


> dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.3.1 (stable) (Wed Mar 6 13:09:19 2024 +0000) on "macos_arm64"
- on macos / Version 14.1 (Build 23B74)
- locale is de-DE

#### Project info

- sdk constraint: '^3.3.1'
- dependencies: web
- dev_dependencies: build_runner, build_web_compilers, lints

#### Process info

|  Memory |  CPU | Elapsed time | Command line                                                                               |
| ------: | ---: | -----------: | ------------------------------------------------------------------------------------------ |
| 3674 MB | 0.6% |     16:24:04 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-232.10203.10 --protocol=analyzer |
|   88 MB | 0.0% |     04:06:19 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-232.10203.10 --protocol=analyzer |
|   32 MB | 0.0% |     16:24:08 | flutter_tools.snapshot daemon                                                              |
|   41 MB | 0.0% |     04:06:20 | flutter_tools.snapshot daemon                                                              |

I found the following reproducible setup:

  1. dart create -t web myapp
  2. Create file lib/src/web.dart with the content
      String webFunction() => "web";
  3. Create file lib/server.dart with the content
    import 'dart:io';
    import 'src/web.dart';
    
    void main() {
      print(Platform.localHostname);
      print(webFunction());
    }
  4. Change web/main.dart contents to
    import 'package:myapp/src/web.dart';
    import 'package:web/helpers.dart';
    
    void main() {
      final element = document.querySelector('#output') as HTMLDivElement;
      element.text = webFunction();
    }
  5. Run dart run build_runner serve web:8080

You should see the skipped compilation warning for web/main.dart although it has no transitive dependency on dart:io.


The bug seems to be somehow related to the src directory:

  • Moving lib/src/web.dart to lib/web.dart solves the problem.
  • Moving lib/src/web.dart to lib/other/web.dart solves the problem.
@jakemac53
Copy link
Contributor

Yes, this happens because of the import to src. We group files together into "modules" to optimize compilation, and that grouping is based on the public imports of the package, as well as things like any file containing a main function gets its own module.

This means any time you have a src/ import that you might end up actually pulling in a module which contains additional libraries which were not depended on by the actual thing you imported.

You can switch to using the "fine" module strategy, where we don't do this grouping, but it will result in slower builds and a LOT more JavaScript files.

In your build.yaml file, something like this (not tested):

targets:
  $default:
    builders:
      build_web_compilers:ddc_modules:
        options:
          strategy: fine

The better option though, would be to make a public entrypoint (lib/web.dart) etc, as you have discovered.

@schultek
Copy link
Author

schultek commented Apr 5, 2024

Interesting. Thanks for your detailed response.

Can you point me to somewhere where this is documented?

I discovered this while building a jaspr integration, so I cannot fix this problem myself but would need to communicate this to the developers using the framework.

@jakemac53
Copy link
Contributor

We should probably add a section to https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings - I am surprised it doesn't already talk about this

@schultek
Copy link
Author

schultek commented Apr 5, 2024

That would be great 😄

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

Successfully merging a pull request may close this issue.

2 participants