我正在构建一个使用Dart 的 AST 库的程序,只要我使用 Dart 解释器运行程序(dart filename.dart
),它就可以正常工作。
一旦我想编译程序(dart compile filename.dart
),程序就无法加载文件,我有这个堆栈跟踪:
#0 _PhysicalFile.readAsStringSync (package:analyzer/file_system/physical_file_system.dart:184)
#1 FolderBasedDartSdk.languageVersion (package:analyzer/src/dart/sdk/sdk.dart:400)
#2 FeatureSetProvider.build (package:analyzer/src/dart/analysis/feature_set_provider.dart:143)
#3 AnalysisDriver._createFileTracker (package:analyzer/src/dart/analysis/driver.dart:1500)
#4 new AnalysisDriver (package:analyzer/src/dart/analysis/driver.dart:291)
#5 ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:119)
#6 ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:94)
#7 new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:55)
#8 _createAnalysisContext (package:analyzer/dart/analysis/utilities.dart:125)
#9 resolveFile (package:analyzer/dart/analysis/utilities.dart:115)
#10 main (package:DartProjects/dartprojects.dart:122)
#11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299)
#12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168)
我查看了源代码以查看错误可能出在哪里,似乎package:analyzer/src/dart/sdk/sdk.dart
它试图获取语言版本文件,但不是使用 PATH 来知道我的 dart sdk 在哪里,而是尝试在其中找到它我的 InteliJ 文件夹,失败了。另外,我尝试在新创建的 VM 上运行它,但它也失败了。
这是产生此输出的代码:
import 'dart:io';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
void main(List<String> arguments) async {
final fileName = Directory.current.path + r'\test.dart';
var source = null;
try {
source = await resolveFile(path: fileName);
} catch (e, s) {
print('${s}');
return;
}
}
谢谢你的帮助。