我正在尝试将大型 Angular 11 库升级到 Angular 12。该项目最初是在 Angular 9 中创建的,但我之前已经成功升级了两个。
当我运行升级命令时,我收到此错误,但我无法找出它的含义或如何纠正它。
npx @angular/cli@12 update @angular/core@12 @angular/cli@12
这是我收到的错误。
In Angular version 12, the type of ActivatedRouteSnapshot.fragment is nullable.
This migration automatically adds non-null assertions to it.
✖ Migration failed: Could not find any tsconfig file. Cannot migrate `ActivatedRouteSnapshot.fragment` accesses.
See "/private/var/folders/c1/r_3z61y511l0cfk3hfw5p969h718gw/T/ng-uRymPw/angular-errors.log" for further details.
我不确定如何告诉它找到 tsconfig.json 文件,因为它当前位于项目的根目录中。
更新:
经过更多窥探,这似乎是 Angular 12 迁移模块之一中的问题。该文件是 /node_modules/@angular/core/schematics/migrations/activated-route-snapshot-fragment/index.js:
当模块尝试访问我的 angular.json 文件并解析构建和测试部分中的所有 tsconfig 路径时,该模块失败。
该方法可以在函数 getProjectTsConfigPaths(tree) 方法中的project_tsconfig_paths.js 中找到。
这就是它失败的地方
function getProjectTsConfigPaths(tree) {
// Start with some tsconfig paths that are generally used within CLI projects. Note
// that we are not interested in IDE-specific tsconfig files (e.g. /tsconfig.json)
const buildPaths = new Set(['src/tsconfig.app.json']);
const testPaths = new Set(['src/tsconfig.spec.json']);
// Add any tsconfig directly referenced in a build or test task of the angular.json workspace.
const workspace = getWorkspaceConfigGracefully(tree);
if (workspace) {
const projects = Object.keys(workspace.projects).map(name => workspace.projects[name]);
for (const project of projects) {
const buildPath = getTargetTsconfigPath(project, 'build');
const testPath = getTargetTsconfigPath(project, 'test');
if (buildPath) {
buildPaths.add(buildPath);
}
if (testPath) {
testPaths.add(testPath);
}
}
}
// Filter out tsconfig files that don't exist in the CLI project.
return {
buildPaths: Array.from(buildPaths).filter(p => tree.exists(p)),
testPaths: Array.from(testPaths).filter(p => tree.exists(p)),
};
}
exports.getProjectTsConfigPaths = getProjectTsConfigPaths;
但是我的 angular.json 文件没有丢失任何 tsConfig 文件路径。
您可能想尝试更新 Node.js。 我遇到了同样的问题,更新 Node.js 解决了我的问题。
我在离子项目中遇到了类似的问题。当我迁移到 Angular 12 时,我遇到了同样的错误,但我的项目仍然没问题并且没有损坏。我的感觉是,如果您遇到此类问题,这不会对您的项目造成重大更改。