[api-extractor] ExtractorConfig fails when bundled into ESM output
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- nodejs, typescript
- Domain
- build-system, tooling
Research direction
Start at the ExtractorConfig._defaultConfig initialization and inspect how schemas/api-extractor-defaults.json is loaded. Reproduce the failure by bundling @microsoft/api-extractor into a single-file ESM output with a listed bundler, then verify that the default schema loads from the bundled output without a runtime filesystem path dependency.
Written by the indexing model from the issue text.
Description
When @microsoft/api-extractor is bundled into a single-file ESM output (e.g. with esbuild, rollup, rolldown, or webpack), the following error is thrown at runtime:
Error: File does not exist: /path/to/bundle-output/schemas/api-extractor-defaults.json
Root cause
ExtractorConfig loads its default config at module initialization time using a __dirname-relative path:
ExtractorConfig._defaultConfig = JsonFile.load(path.join(__dirname, '../schemas/api-extractor-defaults.json'));
__dirname is a CJS-only global — it doesn't exist in ESM. To handle this when bundling CJS code into ESM output, bundlers inject a replacement. For example, rolldown's recommended workaround is to globally define __dirname as import.meta.dirname via transform.define. This replacement resolves to the bundle's output directory rather than the original api-extractor package directory, so the schema file is never found.
Suggested fix
Replace the filesystem read with a static JSON import, which bundlers inline at build time:
import defaultConfig from '../schemas/api-extractor-defaults.json' with { type: 'json' };
ExtractorConfig._defaultConfig = defaultConfig;
This eliminates the runtime filesystem dependency entirely and works correctly whether the package is used directly or bundled.
- Dominant language
- TypeScript
- Stars
- 6.5k
- Forks
- 708
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 48
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/rushstack
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
All issues in microsoft/rushstack
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
ontola/atomic-server#1625 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
melgarafael/DeskcommCRM#1451 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
bug via-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bot:ai-assisted component:compact-js status:untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
midnightntwrk/midnight-sdk#403 ·