1

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.

Showcaselfloyd
  • 790
  • 7
  • 28
  • 1
    in your angular.json under projects."yourProject".architect.build.options.tsconfig: "path/to/tsconfig.json" – Mehyar Sawas Dec 14 '21 at 19:44
  • Thanks for answering me back. Yeah I have it listed in the file, but it's not picking it up then. "build": { "builder": "@angular-devkit/build-angular:ng-packagr", "options": { "tsConfig": "projects/my-project/tsconfig.lib.json", "project": "projects/my-project/ng-package.json" }, "configurations": { "production": { "tsConfig": "projects/my-project/tsconfig.lib.prod.json" } } }, – Showcaselfloyd Dec 14 '21 at 20:11
  • @Showcaselfloyd are you able to fix this issue ? – superB Mar 25 '22 at 11:28
  • @superB Unfortunately no I never found the solution, but I did find (in my case at least) that it got through enough of the upgrade process that my application wasn't entirely broken. So I just went with it as is. Oddly something later I upgraded from Angular 12 to Angular 13 with no problems. – Showcaselfloyd Mar 27 '22 at 14:33

1 Answers1

0

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

McRage
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 11 '22 at 03:59