我要将dart / angular项目升级到dart 2.x / angular5.x。 phpstorm中的示例有效,但是当我构建项目时,出现以下错误:
[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
我按照指南迁移了项目,并且dart分析未显示任何错误
这是我的一些文件:
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
我减少了代码以指示错误,但没有任何变化。即使删除导入语句,我也会收到无法导入ref1的app_component.template.dart错误。
答案 0 :(得分:2)
对我来说同样的问题。清理项目解决了该问题。
pub cache repair
答案 1 :(得分:1)
问题是layout.scss.css的styleUrl。在mac pub / webdev上没有显示任何此错误,但是在Windows机器上却出现以下错误:
[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.
更新了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 {
}