diff --git a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts index 0bc6236aa4d..0607d63b377 100644 --- a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts +++ b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts @@ -300,6 +300,28 @@ export class ExportAnalyzer { return false; } + // If the user configured `bundledPackages` but TypeScript could not + // produce a `packageId` for this module, the bundled-package lookup is + // guaranteed to miss it and the module will be silently treated as + // external (issue #5730). The most common cause is a local package + // whose `package.json` lacks a `"version"` field — TypeScript does not + // assign a `packageId` without one (microsoft/TypeScript#63307). Surface + // the cause with a remediable error rather than producing a confusing + // bundling result. + if (packageName === undefined && this._bundledPackageNames.size > 0) { + throw new InternalError( + `Cannot determine the package name for the module ${JSON.stringify( + moduleSpecifier + )}, but "bundledPackages" is configured. ` + + `This is usually because the resolved package's package.json ` + + `is missing a "version" field — TypeScript does not assign a ` + + `packageId without one (microsoft/TypeScript#63307), so the ` + + `bundledPackages lookup cannot match it. Add a "version" field ` + + `(any value works) to the package's package.json and re-run.\n` + + SourceFileLocationFormatter.formatDeclaration(importOrExportDeclaration) + ); + } + if (resolvedModule.isExternalLibraryImport === undefined) { // This presumably means the compiler couldn't figure out whether the module was external, but we're not // sure how this can happen. diff --git a/common/changes/@microsoft/api-extractor/fix-bundled-packages-missing-version_2026-05-27-19-00.json b/common/changes/@microsoft/api-extractor/fix-bundled-packages-missing-version_2026-05-27-19-00.json new file mode 100644 index 00000000000..44d84268fae --- /dev/null +++ b/common/changes/@microsoft/api-extractor/fix-bundled-packages-missing-version_2026-05-27-19-00.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Throw an actionable InternalError instead of silently failing to bundle when bundledPackages is configured but TypeScript could not assign a packageId to the resolved module (most often because the package's package.json is missing a \"version\" field).", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file