简体   繁体   English

如何在升级期间告诉 Angular 12 我的 tsconfig.json 文件在哪里?

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

I'm trying to upgrade a large size Angular 11 library to Angular 12. Project was original created in Angular 9 but I have successfully upgraded two before.我正在尝试将大型 Angular 11 库升级到 Angular 12。项目最初是在 Angular 9 中创建的,但我之前已经成功升级了两个。

When I run the commend to upgrade I get this error but i've been unable to find out what it means or how to correct it.当我运行推荐升级时,我收到此错误,但我无法找出它的含义或如何纠正它。

npx @angular/cli@12 update @angular/core@12 @angular/cli@12

This is the error I'm receiving.这是我收到的错误。

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.

I'm not sure how to tell it to find the tsconfig.json file, since it's in the root of the project currently.我不确定如何告诉它找到 tsconfig.json 文件,因为它目前位于项目的根目录中。

Update:更新:

So after more snooping it appears to be an issue in one of the Angular 12 migration modules.因此,经过更多窥探之后,Angular 12 迁移模块之一似乎存在问题。 The file is /node_modules/@angular/core/schematics/migrations/activated-route-snapshot-fragment/index.js:该文件是/node_modules/@angular/core/schematics/migrations/activated-route-snapshot-fragment/index.js:

The module is failing when it tries to reach my angular.json file and parse all the tsconfig paths in the build and test sections.该模块在尝试访问我的 angular.json 文件并解析构建和测试部分中的所有 tsconfig 路径时失败。

The method is found here project_tsconfig_paths.js in the function getProjectTsConfigPaths(tree) method.该方法在 function getProjectTsConfigPaths(tree) 方法中的 project_tsconfig_paths.js 中找到。

Here's where it is failing exactly这正是它失败的地方

 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;

But of my angular.json file isn't missing any tsConfig file paths.但是我的 angular.json 文件没有丢失任何 tsConfig 文件路径。

You might want to try updating your Node.js.您可能想尝试更新您的 Node.js。 I had the same issue, and updating Node.js resolved the issue for me.我遇到了同样的问题,更新 Node.js 为我解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM