2

Doing the following import in dart import 'package:http/browser_client.dart'; causes a warning when doing a pub build

****************************************************************
* WARNING: dart:mirrors support in dart2js is experimental,
*          and not recommended.
*          This implementation of mirrors is incomplete,
*          and often greatly increases the size of the generated
*          JavaScript code.
*
* Your app imports dart:mirrors via:
*   index.html_bootstrap.dart => package:myapp => package:http => dart:mirrors
*
* Starting with Dart 1.9, you must use the
* --enable-experimental-mirrors command-line flag to opt-in.
* You can begin using this flag now if mirrors support is critical.
*
* To learn what to do next, please visit:
*    http://dartlang.org/dart2js-reflection
****************************************************************

[Warning from Dart2JS on myapp|web/index.html_bootstrap.dart]:
3 hint(s) suppressed in package:http.
[Dart2JS on myapp|web/index.html_bootstrap.dart]:
5 warning(s) suppressed in package:myapp.
[Warning from Dart2JS]:
web/index.html_bootstrap.dart:
1 methods retained for use by dart:mirrors out of 2361 total methods (0%).
[Info from Dart2JS on myapp|web/index.html_bootstrap.dart]:
packages/http/src/io.dart:9:1:
Import of 'dart:mirrors'.
import 'dart:mirrors';
^^^^^^^^^^^^^^^^^^^^^^

The code using that browser_client is:

var client = new BrowserClient();
client.post(url, body: req.toString())...

Is this something I should be concerned about, or is this one of those pesky warnings that won't go away unless I stop using the http package?

Update:

Looking inside browser_client.dart, I see the following comment:

// TODO(nweiz): Move this under src/, re-export from lib/http.dart, and use this
// automatically from [new Client] once we can create an HttpRequest using
// mirrors on dart2js (issue 18541) and dart2js doesn't crash on pkg/collection
// (issue 18535).

Update:

Running pub help, I see no such flag:

pub help
Pub is a package manager for Dart.

Usage: pub <command> [arguments]

Global options:
-h, --help            Print this usage information.
    --version         Print pub version.
    --[no-]trace      Print debugging information when an error occurs.
    --verbosity       Control output verbosity.

          [all]       Show all output including internal tracing messages.
          [io]        Also show IO operations.
          [normal]    Show errors, warnings, and user messages.
          [solver]    Show steps during version resolution.

-v, --verbose         Shortcut for "--verbosity=all".

Available commands:
  build       Apply transformers to build a package.
  cache       Work with the system cache.
  deps        Print package dependencies.
  downgrade   Downgrade the current package's dependencies to oldest versions.
  get         Get the current package's dependencies.
  global      Work with global packages.
  help        Display help information for Pub.
  publish     Publish the current package to pub.dartlang.org.
  run         Run an executable from a package.
  serve       Run a local web development server.
  upgrade     Upgrade the current package's dependencies to latest versions.
  uploader    Manage uploaders for a package on pub.dartlang.org.
  version     Print pub version.

Calling it directly, pub tells me there is no such flag:

 pub build --enable-experimental-mirrors
Could not find an option named "enable-experimental-mirrors".
Jan Vladimir Mostert
  • 12,380
  • 15
  • 80
  • 137

1 Answers1

4

It will go away when you add the flag it tells you add: --enable-experimental-mirrors

As the message says, mirrors currently bloat the size of the generated JavaScript. This often catches developers unawares, since they rightly expect dart2js to handle this properly. However, this is a non-trivial problem for dart2js to solve. While better solutions are being worked on, mirror support is considered experimental and this warning serves to notify developers to the potential issues involved with using them.

You can add the flag to signal that you are aware of the mirrors issues and are choosing to use them anyway.

Pixel Elephant
  • 20,649
  • 9
  • 66
  • 83
  • I'm on dart 1.8.3, that flag is not available when I do `pub build` – Jan Vladimir Mostert Jan 08 '15 at 21:18
  • 3
    Try enabling it through your pubspec as per http://stackoverflow.com/questions/27720721/how-to-enable-enable-experimental-mirrors-in-dart-build – Pixel Elephant Jan 08 '15 at 21:31
  • That fixes it, thanks! I'll be avoiding mirrors as far as possible until it's no longer an experimental feature. – Jan Vladimir Mostert Jan 08 '15 at 21:37
  • Actually this doesn't fix the real issue. Forcing to use mirror to check if "IOClient" is available when one already imported the browser client IMHO is wrong and causes problems with mirrors. I think this actually is an issue of `http` package that should be reported. – Vittorio Ballestra Oct 17 '15 at 12:42