From b4be623843b7c10b92af951ee779da210f6ed6ac Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 2 Oct 2025 11:34:38 -0700 Subject: [PATCH 1/2] Disable synthetic default imports when ambiguously safe --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cbdbd55660bcd..19be073f6d53f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3809,7 +3809,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // There are _many_ declaration files not written with esmodules in mind that still get compiled into a format with __esModule set // Meaning there may be no default at runtime - however to be on the permissive side, we allow access to a synthetic default member // as there is no marker to indicate if the accompanying JS has `__esModule` or not, or is even native esm - return true; + return hasExportAssignmentSymbol(moduleSymbol); } // TypeScript files never have a synthetic default (as they are always emitted with an __esModule marker) _unless_ they contain an export= statement if (!isSourceFileJS(file)) { From 6ee5131fe964cd704ed5d589f56e26c364d02b94 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 2 Oct 2025 14:08:15 -0700 Subject: [PATCH 2/2] Make a carve-out for node built-ins --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 19be073f6d53f..82af4ae53b10c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3806,9 +3806,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // it definitely is a module and does not have a synthetic default return false; } - // There are _many_ declaration files not written with esmodules in mind that still get compiled into a format with __esModule set - // Meaning there may be no default at runtime - however to be on the permissive side, we allow access to a synthetic default member - // as there is no marker to indicate if the accompanying JS has `__esModule` or not, or is even native esm + if (!file && getSourceFileOfModule(moduleSymbol)?.fileName.includes("/@types/node/")) { + return true; + } return hasExportAssignmentSymbol(moduleSymbol); } // TypeScript files never have a synthetic default (as they are always emitted with an __esModule marker) _unless_ they contain an export= statement