【问题标题】:Making use of package:http/browser_client.dart causes warnings about mirrors使用 package:http/browser_client.dart 会导致有关镜像的警告
【发布时间】:2015-01-09 05:21:04
【问题描述】:

在 dart import 'package:http/browser_client.dart'; 中执行以下导入会导致在执行 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';
^^^^^^^^^^^^^^^^^^^^^^

使用该 browser_client 的代码是:

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

这是我应该关注的问题,还是除非我停止使用 http 包,否则这是不会消失的讨厌警告之一?

更新

查看 browser_client.dart 内部,我看到以下评论:

// 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).

更新

运行 pub help,我没有看到这样的标志:

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.

直接调用,pub告诉我没有这个flag:

 pub build --enable-experimental-mirrors
Could not find an option named "enable-experimental-mirrors".

【问题讨论】:

    标签: dart


    【解决方案1】:

    当你添加它告诉你添加的标志时它会消失:--enable-experimental-mirrors

    正如消息中所说,镜像当前会膨胀生成的 JavaScript 的大小。这经常让开发人员措手不及,因为他们正确地期望 dart2js 能够正确处理这个问题。然而,这对于 dart2js 来说是一个非常重要的问题。虽然正在开发更好的解决方案,但镜像支持被认为是实验性的,此警告用于通知开发人员使用它们时涉及的潜在问题。

    您可以添加标志以表明您知道镜像问题并选择使用它们。

    【讨论】:

    • 我正在使用 dart 1.8.3,当我使用时,该标志不可用 pub build
    • 尝试按照stackoverflow.com/questions/27720721/…通过您的 pubspec 启用它
    • 解决了,谢谢!在它不再是实验性功能之前,我将尽可能避免使用镜像。
    • 实际上这并不能解决真正的问题。当已经导入浏览器客户端恕我直言时,强制使用镜像检查“IOClient”是否可用是错误的,并导致镜像出现问题。我认为这实际上是应该报告的http 包的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2014-10-30
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    相关资源
    最近更新 更多