Skip to content

Commit

Permalink
fix(@schematics/angular): enable TypeScript esModuleInterop by defa…
Browse files Browse the repository at this point in the history
…ult 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)
  • Loading branch information
clydin authored and dgp1130 committed Oct 27, 2023
1 parent d4f37da commit 23c4c5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,<% } %>
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
Expand Down
4 changes: 4 additions & 0 deletions tests/legacy-cli/e2e/initialize/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default async function () {
buildOptimizer: false,
};
});
await updateJsonFile('tsconfig.json', (tsconfig) => {
delete tsconfig.compilerOptions.esModuleInterop;
tsconfig.compilerOptions.allowSyntheticDefaultImports = true;
});
}
}

Expand Down

0 comments on commit 23c4c5e

Please sign in to comment.