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

Unclear error message when using Dart web core libraries in Dart native #47260

Open
mit-mit opened this issue Sep 21, 2021 · 9 comments
Open
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-enhancement A request for a change that isn't a bug

Comments

@mit-mit
Copy link
Member

mit-mit commented Sep 21, 2021

If one imports a Dart web dart: library and tried to run it in a Dart native runtime, an error like this is shown during compilation:

$ dart run
../../.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js.dart:8:1: Error: Not found: 'dart:js'
export 'dart:js' show allowInterop, allowInteropCaptureThis;
^

Could we say something more specific like this?

../../.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/js.dart:8:1: Error: The 'dart:js' library is not supported in Dart native.
export 'dart:js' show allowInterop, allowInteropCaptureThis;

Here's the list of core libraries I think this makes sense for (the last table on the page):
https://dart.dev/guides/libraries#web-platform-libraries

@lrhn
Copy link
Member

lrhn commented Sep 21, 2021

A better error message could be

The web platform library 'dart:js' is not available when compiling to native code.

or, for the other direction:

The native platform library dart:isolate is not available when compiling to web code.

It requires the front-end (I guess) to be aware of all dart: libraries and the platforms they are available for.
(If we get more target platforms and libraries available to more than one, but not all, platforms, then we'll need a different wording - possibly just dropping the initial "web"/"native" before "platform library".)

@lrhn lrhn added area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-enhancement A request for a change that isn't a bug labels Sep 21, 2021
@mit-mit
Copy link
Member Author

mit-mit commented Jan 4, 2022

@johnniwinther wdyt?

@johnniwinther johnniwinther self-assigned this Jan 4, 2022
@johnniwinther
Copy link
Member

We should make this change but it might take while due to technical difficulties.

@krishnatejakanchi
Copy link

My team is getting same issue today, when trying to build for iOS & Android.

It got fixed when we removed this line from js.dart which is there in pub-cache

export 'dart:js' show allowInterop, allowInteropCaptureThis;

@johnniwinther any help please

@mraleph
Copy link
Member

mraleph commented Sep 15, 2022

@krishnatejakanchi you are importing some package that is only going to work on the web (i.e. some of your code is importing package:js/js.dart directly or indirectly). Editing .pub_cache is wrong and you should never do that. The real solution is to identify incorrect dependency.

@krishnatejakanchi
Copy link

I tried running flutter pub deps and got some packages that are dependent on js

build_runner
firebase_core
flutter_native_splash
image_picker
chewie
gleap_sdk

@mraleph Can you please suggest a way, how can i find that incorrect dependency.

@mraleph
Copy link
Member

mraleph commented Sep 15, 2022

@krishnatejakanchi unfortunately there is no easy way to find this dependency AFAIK. The simplest approach you could try is just rename js.dart in your .pub-cache to js.dart.bak (yeah, I know I did not recommend doing that before) and then run build targeting Android/iOS. This should error on the file which tries to import js.dart.

@mraleph
Copy link
Member

mraleph commented Sep 26, 2022

@johnniwinther I would like to suggest a bunch of improvements for the CFE error messaging (if feasible):

  • When importing a platform specific library that does not exist on target platform issue a human readable error message (e.g. dart:js is only available when targeting the web, but this build is targeting native platform. Native platform does not contain a builtin JS runtime and as such can't interoperate with JS libraries.)
  • Visually split errors that originate from .pub-cache dependencies and errors that originate from entry point package itself, e.g. have a header: The following errors occurred when compiling dependencies of your project.
  • Provide import path chain that lead to compilation of a specific dependency: The following errors occured when compiling library 'package:xxx/xxx.dart'. This library is imported through the following sequence of imports: ...

As more and more people starting to use Dart in multiplatform environment it would be great to have better error messaging in place.

@johnniwinther
Copy link
Member

WIP: https://dart-review.googlesource.com/c/sdk/+/261821 that shows the import path (in case of missing dart: libraries for now only)

copybara-service bot pushed a commit that referenced this issue Nov 8, 2022
This special-cases the error for importing/exporting dart: libraries
that are not available on the current platform and includes a detail
description of how the unavailable library was imported in the
context of the error message.

Currently there is no special casing of the message depending on the
unavailable library and the current platform, as this is meant as
a catch-all message. In a follow-up I'll add special casing of the
message for some of these cases.

In response to #47260

Change-Id: Ia296f9ca1b03bf664e12241a139970ef31c8a2d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261821
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants