node.js - 在升级时,我如何告诉 Angular 12 我的 tsconfig.json 文件在哪里?
我正在尝试将一个大型的 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 路径时,它会失败。
该方法位于 project_tsconfig_paths.js 的 getProjectTsConfigPaths(tree) 方法中。
这正是它失败的地方
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 文件路径。
答案#1
你可能想尝试更新你的 Node.js。我遇到过同样的问题,更新 Node.js 解决了我的问题。
答案#2
我在一个Ionic项目中遇到过类似的问题。当我迁移到Angular 12时,我也遇到了同样的错误,但我的项目仍然可以构建。我感觉这不会对你的项目造成破坏性的更改,如果你遇到这类问题的话。