Skip to content

Conversation

@Aukevanoost
Copy link
Contributor

The onDispose callback doesn't close the javascriptTransformer correctly yet. This ensures that all worker pools are cleaned after a disposal.

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Currently the javascriptTransformer is not closed explicitly.

Issue Number: N/A

What is the new behavior?

Like all other parts (compilation and cache), the javascriptTransformer is now closed explicitly.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one NIT

@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Dec 10, 2025
@Aukevanoost
Copy link
Contributor Author

on it!

The onDispose callback doesn't close the javascriptTransformer correctly
yet. This ensures that all worker pools are cleaned after a disposal.
@Aukevanoost Aukevanoost force-pushed the fix/close-javascript-transformer branch from 37d67f6 to 267aa6b Compare December 10, 2025 13:00
@angular-robot angular-robot bot requested a review from alan-agius4 December 10, 2025 13:00
Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this.

@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Dec 10, 2025
@hybrist hybrist merged commit 2e7227b into angular:main Dec 10, 2025
35 checks passed
@hybrist
Copy link
Contributor

hybrist commented Dec 10, 2025

This PR was merged into the repository. The changes were merged into the following branches:

@Aukevanoost
Copy link
Contributor Author

Quick question to @hybrist and @alan-agius4

Would it be possible to also publish this fix in ng v20.3.x?

@alan-agius4
Copy link
Collaborator

Version 20 is in LTS and only security fixes are applied.

@judsonmusic
Copy link

judsonmusic commented Dec 18, 2025

I have created a patch that works for angular 19, 20 etc.

create a file called angular-patch-compiler.js in the project root

/**
 * Angular 19 esbuild cleanup patch
 *
 * Fixes a known issue where JavaScriptTransformer and related
 * resources are not always disposed during ng serve shutdowns,
 * especially in Native Federation + Windows environments.
 *
 * Safe to remove once Angular fixes this upstream.
 */

const path = require('path');

try {
  const compilerPath = path.join(
    process.cwd(),
    'node_modules',
    '@angular',
    'build',
    'src',
    'tools',
    'esbuild',
    'angular',
    'compiler-plugin.js',
  );

  const compilerModule = require(compilerPath);
  const originalCreate = compilerModule.createCompilerPlugin;

  compilerModule.createCompilerPlugin = function (...args) {
    const plugin = originalCreate(...args);
    const originalSetup = plugin.setup;

    plugin.setup = function (build) {
      originalSetup.call(this, build);

      build.onDispose(() => {
        try {
          const { javascriptTransformer, cacheStore, compilation, sharedTSCompilationState } = compilerModule;

          javascriptTransformer?.close?.();
          cacheStore?.close?.();
          compilation?.close?.();
          sharedTSCompilationState?.dispose?.();
        } catch (e) {
          console.error('[Angular Cleanup Patch] dispose failed:', e);
        }
      });
    };

    return plugin;
  };

  console.log('✔ Angular compiler cleanup patch applied');
} catch (e) {
  console.warn('⚠ Angular cleanup patch skipped:', e?.message ?? e);
}

Then use a start command like:
"start": "node patch-angular-compiler.js && npx ng run <mfe-name>:serve-original:local",

Angular.json

make sure you have serve and serve-original with targets:

"serve": {
          "builder": "@angular-architects/native-federation:build",
          "options": {
            "rebuildDelay": 100,
            "dev": true
          },
          "configurations": {
            "local": {
              "target": "<mfe-name>:serve-original:local"
            },
            "deployed": {
              "target": "<mfe-name>:serve-original:deployed"
            }
          },
          "defaultConfiguration": "local"
        },
        "serve-original": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "deployed": {
              "buildTarget": "<mfe-name>:esbuild:deployed"
            },
            "local": {
              "buildTarget": "<mfe-name>:esbuild:local"
            }
          },
          "defaultConfiguration": "local",
          "options": {
            "port": 4210,
            "open": true
          }
        },

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants