Upgrading to Dart2/Angular5 Error importing template.dart

大憨熊 提交于 2020-01-13 20:23:13

问题


I am upgrading my dart/angular project to dart 2.x/angular 5.x. The sample in phpstorm works, but when I build my project, then I am getting following error:

[SEVERE] build_modules|modules on lib/app_component.template.dart:

Bad state: No element
[SEVERE] build_web_compilers|entrypoint on web/main.dart:
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).

Please check the following imports:

`import 'package:mfgapp/app_component.template.dart' as ng;` from mfgapp|web/main.template.dart at 8:1
`import 'package:mfgapp/app_component.template.dart' as ng;` from mfgapp|web/main.dart at 1:1

I migrated the project with the guidlines, and dart analysis does not show any errors

Here are some of my files:

main.dart
import 'package:angular/angular.dart';
import 'package:mfgapp/app_component.template.dart' as ng;

void main() {
  runApp(ng.AppComponentNgFactory);
}

app_component.dart

import 'package:angular/angular.dart';


@Component(
  selector: 'mfgapp',
  styleUrls:  ['package:angular_components/src/components/app_layout/layout.scss.css', 'layout.css', 'app_component.css'],
  templateUrl: 'app_component.html',
)


class AppComponent {

}

pubspec.yaml:

name: mfgapp
description: A web app that uses AngularDart Components

environment:
  sdk: '>=2.0.0-dev.68.0 <3.0.0'

dependencies:
  angular: ^5.0.0-beta
  angular_components: ^0.9.0-beta

dev_dependencies:
  angular_test: ^2.0.0-beta
  build_runner: ^0.9.0
  build_test: ^0.10.2
  build_web_compilers: ^0.4.0
  test: ^1.0.0

I reduced my code to indicate the error, but there is no change. Even if I delete the import statement, I am getting error that app_component.template.dart as ref1 cannot be imported.


回答1:


The same issue for me. Cleaning the project fixed the issue.

pub cache repair



回答2:


Problem was the styleUrl for layout.scss.css. On mac pub/webdev does not show me any error for this, but on my windows machine I am getting following error:

[SEVERE] build_web_compilers|entrypoint on web/main.dart:
Dart2Js finished with:

packages/angular_components/src/components/app_layout/layout.scss.css.shim.dart:
Error: Error reading 'packages/angular_components/src/components/app_layout/layout.scss.css.shim.dart'  (The system cannot find the path specified.

)
Error: Compilation failed.

Updated app_component.dart:

import 'package:angular/angular.dart';


@Component(
  selector: 'mfgapp',
  styleUrls:  ['package:angular_components/app_layout/layout.scss.css', 'layout.css', 'app_component.css'],
  templateUrl: 'app_component.html',
)


class AppComponent {

}


来源:https://stackoverflow.com/questions/51555733/upgrading-to-dart2-angular5-error-importing-template-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!