angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.78k stars 11.98k forks source link

Angular 19: `ng build` fails to find `tsconfig.app.json` during CI/CD pipeline build #28936

Open marklagendijk opened 9 hours ago

marklagendijk commented 9 hours ago

Command

build

Is this a regression?

The previous version in which this bug was not present was

18.2.12

Description

After upgrading to Angular 19 our Azure Pipelines CI/CD build started failing. The Angular build fails because it cannot find/parse tsconfig.app.json.

The failure happens under very specific circumstances. I will describe the high level conditions here, and go into more detail in the 'Minimal Reproduction' below.

The baffling thing for me is that the exception mentions a '.NET build system specific'-folder: PROJECT_NAME/obj/Debug while I verified that the current working directory in which the npm run build command is executed is actually the PROJECT_NAME folder. So where is the Angular build system getting this folder from? And why is it using that folder instead of the current working directory?

Minimal Reproduction

  1. Generate a new Angular application ng new repro-app.
  2. Create a project file in the root of the application directory: application.esproj with the following contents:
    <Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.2039730">
     <PropertyGroup>
       <BuildCommand>echo "$PWD" &amp;&amp; npm run version &amp;&amp; npm run build</BuildCommand>
       <StartupCommand>npm start</StartupCommand>
       <TestCommand>npm run test</TestCommand>
       <JavaScriptTestFramework>Jasmine</JavaScriptTestFramework>
       <BuildOutputFolder>$(MSBuildProjectDirectory)\dist\browser\</BuildOutputFolder>
     </PropertyGroup>
    </Project>
  3. Reference this project from a normal .NET project file.
  4. Build the .NET project in an Azure Pipeline with the ubuntu-24.04 vmImage

Exception or Error

❯ Building...
  ✔ Building...
  Application bundle generation failed. [6.198 seconds]

  ▲ [WARNING] TypeScript compiler options 'module' values 'CommonJS', 'UMD', 'System' and 'AMD' are not supported. [plugin angular-compiler]

    The 'module' option will be set to 'ES2022' instead.

  ▲ [WARNING] TypeScript compiler options 'target' and 'useDefineForClassFields' are set to 'ES2022' and 'false' respectively by the Angular CLI. [plugin angular-compiler]

      tsconfig.app.json:0:0:
        0 │ 
          ╵ ^

    To control ECMA version and features use the Browserslist configuration. For more information, see https://angular.dev/tools/cli/build#configuring-browser-compatibility

✘ [ERROR] TS500 : error : ENOENT: no such file or directory, stat '/home/vsts/work/1/s/PMP.PortalApp/obj/Debug' [/home/vsts/work/1/s/PMP.PortalApp/PMP.PortalApp.esproj]
      at Object.statSync (node:fs:1658:25)
      at NodeJSFileSystem.stat (file:///home/vsts/work/1/s/PMP.PortalApp/node_modules/@angular/compiler-cli/bundles/chunk-37JMVF7H.js:346:16)
      at file:///home/vsts/work/1/s/PMP.PortalApp/node_modules/@angular/compiler-cli/bundles/chunk-37JMVF7H.js:405:23
      at visitDirectory (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:22130:36)
      at Object.matchFiles (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:22123:5)
      at Object.readDirectory (file:///home/vsts/work/1/s/PMP.PortalApp/node_modules/@angular/compiler-cli/bundles/chunk-37JMVF7H.js:395:12)
      at getFileNamesFromConfigSpecs (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:42914:29)
      at getFileNames (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:42407:23)
      at parseJsonConfigFileContentWorker (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:42311:16)
      at Object.parseJsonConfigFileContent (/home/vsts/work/1/s/PMP.PortalApp/node_modules/typescript/lib/typescript.js:42244:10) [plugin angular-compiler]

/home/vsts/work/1/.nuget/packages/microsoft.visualstudio.javascript.sdk/1.0.2039730/Sdk/Sdk.targets(184,5): error MSB3073: The command "npm run version && npm run build" exited with code 1. [/home/vsts/work/1/s/PMP.PortalApp/PMP.PortalApp.esproj]

Your Environment

Angular CLI: 19.0.1
  Node: 22.11.0
  Package Manager: npm 10.9.0
  OS: linux x64

  Angular: 19.0.0
  ... animations, cdk, common, compiler, compiler-cli, core, forms
  ... material, material-luxon-adapter, platform-browser
  ... platform-browser-dynamic, router

  Package                         Version
  ---------------------------------------------------------
  @angular-devkit/architect       0.1900.1
  @angular-devkit/build-angular   19.0.1
  @angular-devkit/core            19.0.1
  @angular-devkit/schematics      19.0.1
  @angular/build                  19.0.1
  @angular/cli                    19.0.1
  @schematics/angular             19.0.1
  rxjs                            7.8.1
  typescript                      5.6.3
  zone.js                         0.15.0

Anything else relevant?

No response

marklagendijk commented 9 hours ago

I realize that this bug report is very specific and hard to reproduce. I reported it anyway because:

  1. Other people may experience a similar issue under different circumstances, and add extra information that makes it easier to reproduce.
  2. The issue might have a cause that is obvious to someone more familiar with the Angular build system.
alan-agius4 commented 8 hours ago

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

This might be related to your directory structure so its really important to get an accurate repro to diagnose this.