From 6a19c217eaebf9c0bffba8482545efc375fd2a8a Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:06:33 -0500 Subject: [PATCH] fix(@angular/build): warn when using both `isolatedModules` and `emitDecoratorMetadata` If both the `isolatedModules` and `emitDecoratorMetadata` Typescript options are enabled within a project, a warning will now be issued explaining that not all metadata may be emitting for each decorator. Isolated modules may not have access to non-local type information that would otherwise be needed for complete metadata emit. The `emitDecoratorMetadata` option is not required by Angular and can cause runtime errors due to its underlying implementation when used with ES2015+ output. The option is only compatible with the experimental decorators and cannot be used with standard decorators. New Angular projects also do not enable this option. (cherry picked from commit 61e8185ab0081ca01a849055b3050f2456af8c23) --- .../src/tools/esbuild/angular/compiler-plugin.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts b/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts index 740c2d119b5a..798adc090f8e 100644 --- a/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts +++ b/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts @@ -689,6 +689,20 @@ function createCompilerOptionsTransformer( }); } + if (compilerOptions.isolatedModules && compilerOptions.emitDecoratorMetadata) { + setupWarnings?.push({ + text: `TypeScript compiler option 'isolatedModules' may prevent the 'emitDecoratorMetadata' option from emitting all metadata.`, + location: null, + notes: [ + { + text: + `The 'emitDecoratorMetadata' option is not required by Angular` + + 'and can be removed if not explictly required by the project.', + }, + ], + }); + } + // Synchronize custom resolve conditions. // Set if using the supported bundler resolution mode (bundler is the default in new projects) if (compilerOptions.moduleResolution === 100 /* ModuleResolutionKind.Bundler */) {