Skip to content

Custom builders using @angular-devkit/build-angular cannot resolve downstream packages when compiled using tsc #27902

Open

Description

Command

other

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

17.3

Description

We have a custom builder for our angular project that has worked smoothly since Angular 8. We recently upgraded from Angular 15 to Angular 18 and tsc now throws errors when attempting to compile the builder. The errors thrown suggest changing the "moduleResolution" setting in tsconfig.builders.json, but each setting results in different downstream module resolution problems in the @angular-devkit/build-angular package.

Example error:

node_modules/@angular-devkit/build-angular/src/builders/browser/index.d.ts:8:36 - error TS2307: Cannot find module '@angular/build/private' or its corresponding type declarations.
There are types at '<path/to/project>/node_modules/@angular/build/src/private.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.
8 import { IndexHtmlTransform } from '@angular/build/private';

The full set of errors is pasted below.

I've attempted to change tsconfig.builders.json to use

  • module: nodenext, moduleResolution: nodenext
  • module: es6, moduleResolution: bundler

But each of these yields a different set of errors.

Minimal Reproduction

Minimal reproduction repository: https://github.com/bowles-tyler-b/Angular8-failed-tsc-builder

After running "npm install", run the command "npm run compile" to reproduce the errors

Exception or Error

node_modules/@angular-devkit/build-angular/src/builders/browser/index.d.ts:8:36 - error TS2307: Cannot find module '@angular/build/private' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/private.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

8 import { IndexHtmlTransform } from '@angular/build/private';
                                     ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@angular-devkit/build-angular/src/builders/dev-server/builder.d.ts:9:45 - error TS2307: Cannot find module '@angular/build' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

9 import type { DevServerBuilderOutput } from '@angular/build';
                                              ~~~~~~~~~~~~~~~~

node_modules/@angular-devkit/build-angular/src/builders/dev-server/builder.d.ts:10:41 - error TS2307: Cannot find module '@angular/build/private' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/private.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

10 import { type IndexHtmlTransform } from '@angular/build/private';
                                           ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@angular-devkit/build-angular/src/builders/dev-server/index.d.ts:8:40 - error TS2307: Cannot find module '@angular/build' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

8 import { DevServerBuilderOutput } from '@angular/build';
                                         ~~~~~~~~~~~~~~~~

node_modules/@angular-devkit/build-angular/src/index.d.ts:11:61 - error TS2307: Cannot find module '@angular/build' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

11 export { buildApplication, ApplicationBuilderOptions } from '@angular/build';
                                                               ~~~~~~~~~~~~~~~~

node_modules/@angular-devkit/build-angular/src/tools/webpack/utils/stats.d.ts:8:40 - error TS2307: Cannot find module '@angular/build/private' or its corresponding type declarations.
  There are types at '<path/to/project>/node_modules/@angular/build/src/private.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

8 import { BudgetCalculatorResult } from '@angular/build/private';
                                         ~~~~~~~~~~~~~~~~~~~~~~~~


Found 6 errors in 5 files.

Errors  Files
     1  node_modules/@angular-devkit/build-angular/src/builders/browser/index.d.ts:8
     2  node_modules/@angular-devkit/build-angular/src/builders/dev-server/builder.d.ts:9
     1  node_modules/@angular-devkit/build-angular/src/builders/dev-server/index.d.ts:8
     1  node_modules/@angular-devkit/build-angular/src/index.d.ts:11
     1  node_modules/@angular-devkit/build-angular/src/tools/webpack/utils/stats.d.ts:8

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 18.0.5
Node: 20.14.0
Package Manager: npm 10.7.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.5
@angular-devkit/build-angular   18.0.5
@angular-devkit/core            18.0.5
@angular-devkit/schematics      18.0.5
@angular/cli                    18.0.5
@schematics/angular             18.0.5
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.7

Anything else relevant?

Adding skipLibCheck to the ts compiler options will suppress the error; this is a workaround now, but reduces type safety in the custom builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions