angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open bowles-tyler-b opened this issue 1 year ago • 6 comments

Command

other

Is this a regression?

  • [X] 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.

bowles-tyler-b avatar Jun 21 '24 20:06 bowles-tyler-b

Have you found a solution to this problem?

onechvoglod avatar Jul 18 '24 17:07 onechvoglod

Any plans or idea if/when this will be addressed?

zwarag avatar Aug 01 '24 08:08 zwarag

I'm fully stuck because of this problem. Any idea of workaround, without downgrading angular to 17 ?

Tsuna58 avatar Sep 18 '24 20:09 Tsuna58

You could use skipLibCheck as a workaround.

alan-agius4 avatar Sep 18 '24 20:09 alan-agius4

You could use skipLibCheck as a workaround.

Yes, I mentioned that in the original post. This is what we're doing for now, but it does of course reduce type safety.

bowles-tyler-b avatar Sep 18 '24 20:09 bowles-tyler-b

Thank you ! I hadn't seen it. You've just saved my evening.

Tsuna58 avatar Sep 18 '24 20:09 Tsuna58

Yo can use npm i --legacy-peer-deps true

shaheedac avatar Nov 05 '24 06:11 shaheedac

Closed via #29431

alan-agius4 avatar Jan 21 '25 15:01 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.