简体   繁体   中英

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.

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.

Update:

So after more snooping it appears to be an issue in one of the Angular 12 migration modules. The file is /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.

The method is found here project_tsconfig_paths.js in the function getProjectTsConfigPaths(tree) method.

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.

You might want to try updating your Node.js. I had the same issue, and updating Node.js resolved the issue for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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