Skip to content

No longer includes externalDependencies in esbuild exclusions #30048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
OysteinAmundsen opened this issue Apr 7, 2025 · 2 comments · Fixed by #30059
Closed
1 task done

No longer includes externalDependencies in esbuild exclusions #30048

OysteinAmundsen opened this issue Apr 7, 2025 · 2 comments · Fixed by #30059
Assignees

Comments

@OysteinAmundsen
Copy link

OysteinAmundsen commented Apr 7, 2025

Command

serve

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

19.2.1

Description

The bug is here: https://github.com/angular/angular-cli/pull/29753/files#diff-725bf17eb0a0bed74c9aaca5f4c4ff2b2239a664a4baac4b29a43d961069adf7

Previously, the call to setExternalMetadata contained everything included in angular.json "target.build.options.externalDependencies". It no longer does.

If I add for instance

"externalDependencies": [
  "class-transformer",
  "class-validator"
],

to my angular.json, and add a console.log right before the call to setExternalMetadata in @angular/build/src/builders/application/execute-build.js like this:
19.2.1

        const { externalConfiguration, externalImports: { browser, server }, } = bundlingResult;
        const implicitBrowser = browser ? [...browser] : [];
        const implicitServer = server ? [...server] : [];
        // TODO: Implement wildcard externalConfiguration filtering
        console.log('External configuration: ', externalConfiguration);
        // ==> ['class-transformer', 'class-validator']
        executionResult.setExternalMetadata(externalConfiguration
            ? implicitBrowser.filter((value) => !externalConfiguration.includes(value))
            : implicitBrowser, externalConfiguration
            ? implicitServer.filter((value) => !externalConfiguration.includes(value))
            : implicitServer, externalConfiguration);

19.2.2

        const exclusionsPrefixes = externalConfiguration.map((exclusion) => exclusion + '/');
        const exclusions = new Set(externalConfiguration);
        const explicitExternal = new Set();
        ...
        console.log('External configuration: ', bundlingResult.externalConfiguration, [...explicitExternal]);
        // ==> ['class-transformer', 'class-validator'], []
        executionResult.setExternalMetadata(implicitBrowser, implicitServer, [...explicitExternal]);

I can see that buildingResult.externalConfiguration contains my externalDependencies, but [...explicitExternal] does not.

It seems that the change tries to collect known dependencies on client or server side and checks the result agains the externalDependencies. But if the dependencies are not known ahead of time, it will ignore them in the output. This makes SSR configurations using frameworks like NestJS hard to use.

Minimal Reproduction

Example repo:

https://github.com/OysteinAmundsen/home

Try to bun install && bun start - it works fine.
Try to upgrade @angular-devkit/build-angular to 19.2.2 and bun install && bun start. It breaks with

Exception or Error

Could not resolve "class-transformer"

Your Environment

$ ng version

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


Angular CLI: 19.2.6
Node: 22.14.0
Package Manager: npm 10.9.2
OS: win32 x64

Angular: 19.2.5
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.1
@angular-devkit/build-angular   19.2.1
@angular-devkit/core            19.2.6
@angular-devkit/schematics      19.2.6
@angular/cli                    19.2.6
@angular/ssr                    19.2.6
@schematics/angular             19.2.6
rxjs                            7.8.2
typescript                      5.7.3
zone.js                         0.15.0

Anything else relevant?

No response

@alan-agius4
Copy link
Collaborator

I tried to take a look at the project provided, but the project doesn't build

Application bundle generation failed. [4.103 seconds]

✘ [ERROR] TS2688: Cannot find type definition file for 'Multer'.
  The file is in the program because:
    Entry point of type library 'Multer' specified in compilerOptions [plugin angular-compiler]


✘ [ERROR] TS2694: Namespace 'global.Express' has no exported member 'Multer'. [plugin angular-compiler]

    apps/backend/src/app/transcribe/transcribe.controller.ts:17:44:
      17 │   transscribe(@UploadedFile() file: Express.Multer.File) {
         ╵                                             ~~~~~~

@OysteinAmundsen
Copy link
Author

Sorry about that @alan-agius4. Some missing typeRoots got lost here, nescessary on linux but obviously not required on windows.
Project runs as it should now.

@alan-agius4 alan-agius4 self-assigned this Apr 8, 2025
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Apr 8, 2025
…s in vite-dev-server

This fix ensures that transitive external dependencies are correctly recognized and excluded during development builds with the Vite dev server. Previously, some dependencies were mistakenly bundled.

Closes angular#30048
alan-agius4 added a commit that referenced this issue Apr 10, 2025
…s in vite-dev-server

This fix ensures that transitive external dependencies are correctly recognized and excluded during development builds with the Vite dev server. Previously, some dependencies were mistakenly bundled.

Closes #30048

(cherry picked from commit 6e6315d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants