Skip to content

fix(@angular-devkit/build-angular): ensure esbuild-based builders exclusively produce ESM output #27431

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

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,18 @@ function createCompilerOptionsTransformer(
): Parameters<AngularCompilation['initialize']>[2] {
return (compilerOptions) => {
// target of 9 is ES2022 (using the number avoids an expensive import of typescript just for an enum)
if (compilerOptions.target === undefined || compilerOptions.target < 9) {
if (compilerOptions.target === undefined || compilerOptions.target < 9 /** ES2022 */) {
// If 'useDefineForClassFields' is already defined in the users project leave the value as is.
// Otherwise fallback to false due to https://github.com/microsoft/TypeScript/issues/45995
// which breaks the deprecated `@Effects` NGRX decorator and potentially other existing code as well.
compilerOptions.target = 9;
compilerOptions.target = 9 /** ES2022 */;
compilerOptions.useDefineForClassFields ??= false;

// Only add the warning on the initial build
setupWarnings?.push({
text:
'TypeScript compiler options "target" and "useDefineForClassFields" are set to "ES2022" and ' +
'"false" respectively by the Angular CLI.',
`TypeScript compiler options 'target' and 'useDefineForClassFields' are set to 'ES2022' and ` +
`'false' respectively by the Angular CLI.`,
location: { file: pluginOptions.tsconfig },
notes: [
{
Expand Down Expand Up @@ -507,6 +507,15 @@ function createCompilerOptionsTransformer(
compilerOptions.incremental = false;
}

if (compilerOptions.module === undefined || compilerOptions.module < 5 /** ES2015 */) {
compilerOptions.module = 7; /** ES2022 */
setupWarnings?.push({
text: `TypeScript compiler options 'module' values 'CommonJS', 'UMD', 'System' and 'AMD' are not supported.`,
location: null,
notes: [{ text: `The 'module' option will be set to 'ES2022' instead.` }],
});
}

return {
...compilerOptions,
noEmitOnError: false,
Expand Down