Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#5,864 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
nodejs, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
6.5k
Fork
708
Merge medio
5g 19h
PR unite (30g)
48

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/rushstack

Tutte le issue di microsoft/rushstack

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.