簡體   English   中英

如何在升級期間告訴 Angular 12 我的 tsconfig.json 文件在哪里?

[英]How do I tell Angular 12 during an upgrade where my tsconfig.json file is?

我正在嘗試將大型 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 路徑時失敗。

該方法在 function 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 為我解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM