angular / angular

Deliver web apps with confidence 🚀
https://angular.dev
MIT License
95.18k stars 24.97k forks source link

Standalone migration does not find any files because it uses tsconfig.spec.json #50483

Open aikrez opened 1 year ago

aikrez commented 1 year ago

Command

generate

Is this a regression?

The previous version in which this bug was not present was

No response

Description

The standalone migration generator is using the tsconfig.spec.json and therefor does not find any files to migrate.

Minimal Reproduction

1 Create a new project with the Angular cli 2 add a new component and module and import it in app.module

3 Run the command ng g @angular/core:standalone Choose the type of migration: (Use arrow keys)

Convert all components, directives and pipes to standalone Which path in your project should be migrated? (./) ./

Result � Automated migration step has finished! � IMPORTANT! Please verify manually that your application builds and behaves as expected. See https://angular.io/guide/standalone-migration for more information. UPDATE src/app/shouldremove/whatever/whatever.component.spec.ts (628 bytes)

The migration script only checks the files in the tsconfig.spec.json

When I change (ofc not the way to do it) "include": [ "src/**/*.spec.ts", "src/**/*.d.ts" ]

to "include": [ "src/**/*.ts", "src/**/*.d.ts" ]

it works correctly. The generator is using the wrong tsconfig file

Exception or Error

No response

Your Environment

Angular CLI: 16.0.3
Node: 18.16.0
Package Manager: npm 9.5.1
OS: win32 x64

Angular: 16.0.3
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.3
@angular-devkit/build-angular   16.0.3
@angular-devkit/core            16.0.3
@angular-devkit/schematics      16.0.3
@schematics/angular             16.0.3
rxjs                            7.8.1
typescript                      5.0.4

Anything else relevant?

No response

crisbeto commented 1 year ago

What does your angular.json look like? The migration is set up to look for all tsconfigs in the angular.json.

aikrez commented 1 year ago

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "angular-sixteen": {
            "projectType": "application",
            "schematics": {},
            "root": "",
            "sourceRoot": "src",
            "prefix": "app",
            "architect": {
                "build": {
                    "builder": "@angular-devkit/build-angular:browser",
                    "options": {
                        "outputPath": "dist/angular-sixteen",
                        "index": "src/index.html",
                        "main": "src/main.ts",
                        "polyfills": [
                            "zone.js"
                        ],
                        "tsConfig": "tsconfig.app.json",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets"
                        ],
                        "styles": [
                            "src/styles.css"
                        ],
                        "scripts": []
                    },
                    "configurations": {
                        "production": {
                            "budgets": [
                                {
                                    "type": "initial",
                                    "maximumWarning": "500kb",
                                    "maximumError": "1mb"
                                },
                                {
                                    "type": "anyComponentStyle",
                                    "maximumWarning": "2kb",
                                    "maximumError": "4kb"
                                }
                            ],
                            "outputHashing": "all"
                        },
                        "development": {
                            "buildOptimizer": false,
                            "optimization": false,
                            "vendorChunk": true,
                            "extractLicenses": false,
                            "sourceMap": true,
                            "namedChunks": true
                        }
                    },
                    "defaultConfiguration": "production"
                },
                "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "configurations": {
                        "production": {
                            "browserTarget": "angular-sixteen:build:production"
                        },
                        "development": {
                            "browserTarget": "angular-sixteen:build:development"
                        }
                    },
                    "defaultConfiguration": "development"
                },
                "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                        "browserTarget": "angular-sixteen:build"
                    }
                },
                "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                        "polyfills": [
                            "zone.js",
                            "zone.js/testing"
                        ],
                        "tsConfig": "tsconfig.spec.json",
                        "assets": [
                            "src/favicon.ico",
                            "src/assets"
                        ],
                        "styles": [
                            "src/styles.css"
                        ],
                        "scripts": []
                    }
                }
            }
        }
    }
}```
bougwal commented 7 months ago

Are there any updates on this issue ?

sannyjacobsson commented 6 months ago

I have the same issue. Did you ever find any workable solution?

aikrez commented 6 months ago

I have the same issue. Did you ever find any workable solution?

I only have the workaround that I provided in the first post. I haven't looked into the migration since then.

selected-pixel-jameson commented 4 months ago

I also had this issue. The workaround solved it.

klopsknoedel commented 4 months ago

I ran into the same issue on my current project (Angular 17.2) and it seems like the main cause is not that only tsconfig.spec.json will be used but whatever tsconfig is defined in "architect" > "test". So just for the migration procedure you could just change tsconfig.spec.json to tsconfig.app.json and switch it back when you're done.

At this point this issue is way bigger in our project as we don't have a test configuration because we are using jest. And any other config gets ignored. If I try to migrate to standalone I get the error Could not find any tsconfig file. Cannot run the standalone migration.. There is a esbuild config containing tsConfig: tsconfig.app.json (~even build won't fix it~) which gets ignored but as soon as I add the test section the migration starts as expected with whatever tsconfig I define in there.

P.S. Just did a test and temporarily switched from esbuild to build and the migration went well. Anyway, I guess esbuild should be added to the accepted project.targets: https://github.com/angular/angular/blob/e92354570d6c171a5048dc5ce704596ce065b540/packages/core/schematics/utils/project_tsconfig_paths.ts#L26

ankitmvp commented 2 weeks ago

"include": [ "src/*/.ts", "src/*/.d.ts" ]

The workaround works .. You saved my day