Skip to content

Commit 23c4c5e

Browse files
clydindgp1130
authored andcommitted
fix(@schematics/angular): enable TypeScript esModuleInterop by default for ESM compliance
The `esModuleInterop` TypeScript option is a TypeScript recommended option that ensures that TypeScript emits compliant ESM code when transforming namespace and default imports. This is important for new projects because they now use the `application` builder which emits full ESM code. Not using this option with certain third-party packages (e.g., `moment`) can result in build warnings and the potential for runtime failure. For existing applications that are considering migrating, information pertaining to this situation will be available within the documentation. Since the `allowSyntheticDefaultImports` is implied and automatically enabled when `esModuleInterop` is enabled, the previous option has been replaced with this one. Reference: https://www.typescriptlang.org/tsconfig#esModuleInterop (cherry picked from commit 00872ea)
1 parent d4f37da commit 23c4c5e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/schematics/angular/workspace/files/tsconfig.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"noPropertyAccessFromIndexSignature": true,
1010
"noImplicitReturns": true,
1111
"noFallthroughCasesInSwitch": true,<% } %>
12-
"allowSyntheticDefaultImports": true,
12+
"esModuleInterop": true,
1313
"sourceMap": true,
1414
"declaration": false,
1515
"downlevelIteration": true,

tests/legacy-cli/e2e/initialize/500-create-project.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export default async function () {
4545
buildOptimizer: false,
4646
};
4747
});
48+
await updateJsonFile('tsconfig.json', (tsconfig) => {
49+
delete tsconfig.compilerOptions.esModuleInterop;
50+
tsconfig.compilerOptions.allowSyntheticDefaultImports = true;
51+
});
4852
}
4953
}
5054

0 commit comments

Comments
 (0)