迁移到angulardart 4.0.0失败,并显示消息Unsupported operation:使用' angular2'变压器是必需的

时间:2018-04-23 15:01:19

标签: angular-dart

我刚将我的项目从angulardart 3.1.0迁移到4.0.0我的pubspec.yaml是:

dependencies:
  angular2: ^3.1.0
  http: ^0.11.0
  #...other deps
dev_dependencies:
  browser: ^0.10.0
  dart_to_js_script_rewriter: ^1.0.1
transformers:
- angular2:
    platform_directives:
    - 'package:angular2/common.dart#COMMON_DIRECTIVES'
    platform_pipes:
    - 'package:angular2/common.dart#COMMON_PIPES'
    entry_points: web/main.dart
    resolved_identifiers:
        BrowserClient: 'package:http/browser_client.dart'
        Client: 'package:http/http.dart'
- dart_to_js_script_rewriter
- $dart2js:
      sourceMaps: true

并成为:

dependencies:
  angular: ^4.0.0
  angular_router: ^1.0.2
  angular_components: ^0.8.0
  http: ^0.11.0
  #... other deps
dev_dependencies:
  browser: ^0.10.0
  dart_to_js_script_rewriter: ^1.0.1
transformers:
- angular:
    entry_points: web/main.dart
- $dart2js:
      sourceMaps: true
- dart_to_js_script_rewriter

我的问题是在dartium(版本50.0.2661.108(64位)"在mac")上我在启动时出现此错误:

VM970:1 Uncaught Unhandled exception:
Unsupported operation: Using the 'angular2' transformer is required.

Please see https://webdev.dartlang.org/angular/tutorial for setup instructions,
and ensure your 'pubspec.yaml' file is configured to invoke the 'angular2'
transformer on your application's entry point.
#0      bootstrap (package:angular/src/platform/bootstrap.dart:107:5)
#1      main (http://localhost:3000/web/main.dart:50:3)
<asynchronous suspension>

当我尝试运行pub build时,它无法识别ngIf和ngFor:

错误:模板分析错误:UserListPopup的第13行第11行:ParseErrorLevel.FATAL:属性绑定ngIf未被嵌入式模板上的任何指令使用

作为参考,这是我现在的整个pubspec.yaml:

name: share_place
description: Collaborate around your documents in a seamless way
version: 0.0.1
environment:
  sdk: '>=1.24.0 <2.0.0'
dependencies:
  angular: ^4.0.0
  angular_router: ^1.0.2
  angular_components: ^0.8.0
  http: ^0.11.0
  stream_transformers: ^0.3.0
  http_server: any
  js: ^0.6.0
  uuid: ^0.5.3
  croppie_dart: ^2.4.1
  stack_trace: any
  source_map_stack_trace: any
  source_maps: any
  validator: ">=0.0.4 <0.1.0"
dev_dependencies:
  browser: ^0.10.0
  dart_to_js_script_rewriter: ^1.0.1
transformers:
- angular:
    entry_points:
    - web/main.dart
- $dart2js:
      sourceMaps: true
- dart_to_js_script_rewriter

这在我测试升级dart(windows和mac)的两台机器上是可重现的。我仍然没有尝试卸载重新安装

这里是我的main.dart的内容,我觉得没什么特别的:

int version;

Future loadLastVersion() async {
  String version = await html.HttpRequest.getString('/sp/util/loadAppVersion');
  if (conf.appVersion != version) {
    if (conf.isWebApp) {
      html.window.alert("you have an old version : ${conf.appVersion} we must load the new version :${version}");
      html.window.location.assign("${conf.remoteUrl}/v${version}");
    } else {
      html.window.alert("A new version ${version} is available! Please download it from : https://www.share.place/downloads");
    }
  }
}

Future main() async {
  loadLastVersion();

  Logger.root.level = Level.FINE;
  Logger.root.onRecord.listen((LogRecord rec) {
    if (rec.level == Level.SEVERE || rec.level == Level.WARNING)
      html.window.console.error('${rec.level.name} - ${rec.loggerName} : ${rec.message}');
    else if (rec.level == Level.INFO)
      html.window.console.info('${rec.level.name} - ${rec.loggerName} : ${rec.message}');
    else
      html.window.console.debug('${rec.level.name} - ${rec.loggerName} : ${rec.message}');
  });

  bootstrap(AppComponent, [provide(Client, useClass: BrowserDataService), provide(ExceptionHandler, useClass: ErrorHandler), Environment, EventBus]
      // Using a real back end? Import browser_client.dart and change the above to
      // [provide(Client, useFactory: () => new BrowserClient(), deps: [])]
      );
}

1 个答案:

答案 0 :(得分:2)

不再支持

platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'

您需要添加到@Component(...)

directives: const [COMMON_DIRECTIVES]
pipes: const [COMMON_PIPES]

到您使用它们的每个组件。