Bug Report
Currently, allowSyntheticDefaultImports is not respected when a file is ModuleKind.ESNext.
A lot of people in the ecosystem incorrectly define ES modules using export = and so this causes some issues.
The root cause is this usageMode === ModuleKind.ESNext in checker.ts. Removing that expression fixes the issue:
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean, usage: Expression) {
const usageMode = file && getUsageModeForExpression(usage);
if (file && usageMode !== undefined) {
const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
if (usageMode === ModuleKind.ESNext || result) {
return result;
}
// fallthrough on cjs usages so we imply defaults for interop'd imports, too
}
🔎 Search Terms
allowSyntheticDefaultImports ModuleKind.ESNext
🕗 Version & Regression Information
🙁 Actual behavior
Errors like the following, even though allowSyntheticDefaultImports is true:
Module '"https://esm.sh/v96/@types/sanitize-html@2.6.2/index.d.ts"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
🙂 Expected behavior
No type errors, but maybe it could be argued the error message would improve to not mention the allowSyntheticDefaultImports flag. I would argue for no type errors because of the prevalance of people incorrectly using export = to describe ES modules.
Bug Report
Currently,
allowSyntheticDefaultImportsis not respected when a file isModuleKind.ESNext.A lot of people in the ecosystem incorrectly define ES modules using
export =and so this causes some issues.The root cause is this
usageMode === ModuleKind.ESNextin checker.ts. Removing that expression fixes the issue:🔎 Search Terms
allowSyntheticDefaultImports ModuleKind.ESNext
🕗 Version & Regression Information
🙁 Actual behavior
Errors like the following, even though
allowSyntheticDefaultImportsis true:🙂 Expected behavior
No type errors, but maybe it could be argued the error message would improve to not mention the
allowSyntheticDefaultImportsflag. I would argue for no type errors because of the prevalance of people incorrectly usingexport =to describe ES modules.