[api-extractor] ExtractorConfig fails when bundled into ESM output

Open
#5,864 0 comments 0 reactions 0 assignees View on GitHub

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

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/rushstack

All issues in microsoft/rushstack

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.