Type declarations break under moduleResolution: node16/nodenext (extensionless relative imports in ESM .d.ts files)

Aperta
#765 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Start by reproducing the TypeScript 5.x or 6.0.3 example with node16 or nodenext resolution and --traceResolution. Inspect dist/lib/pdfium/index.d.ts and the other published declaration files in @embedpdf/engines and @embedpdf/models. Done means the declaration re-exports resolve under ESM rules and the named imports compile without TS2305 or TS2834.

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

Descrizione

Summary

@embedpdf/engines and @embedpdf/models (2.15.0) are unusable at the type level in projects using TypeScript's node16/nodenext module resolution. Every named import fails with TS2305 ("has no exported member") even though the API exists and works at runtime.

The published .d.ts tree uses extensionless relative specifiers (export * from './engine') inside packages declared "type": "module". Under node16/nodenext, TypeScript applies ESM resolution rules to those declaration files and requires explicit .js extensions, so every relative re-export fails to resolve and the entry-point modules end up with no members. The runtime JS is bundled into chunks with resolvable specifiers, which is why this only bites the type checker.

Reproduction

// package.json
{ "type": "module", "dependencies": { "@embedpdf/engines": "2.15.0" } }
// tsconfig.json
{ "compilerOptions": { "module": "nodenext", "moduleResolution": "nodenext", "noEmit": true } }
// index.ts
import { PdfEngine, PdfiumNative } from '@embedpdf/engines/pdfium';
import { createNodeImageDataToBufferConverter } from '@embedpdf/engines/converters';
error TS2305: Module '"@embedpdf/engines/pdfium"' has no exported member 'PdfEngine'.
error TS2305: Module '"@embedpdf/engines/pdfium"' has no exported member 'PdfiumNative'.
error TS2305: Module '"@embedpdf/engines/converters"' has no exported member 'createNodeImageDataToBufferConverter'.

Running with --traceResolution shows the underlying failures inside the package's own declaration files, e.g. resolving dist/lib/pdfium/index.d.ts:

error TS2834: Relative import paths need explicit file extensions in ECMAScript imports
when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path.
...
======== Module name './engine' was not resolved. ========

Reproduced with TypeScript 5.x and 6.0.3.

Root cause

dist/lib/pdfium/index.d.ts (and most of the declaration tree) re-exports without extensions:

export * from './engine';
export * from './helper';
export * from '../converters/types';
export * from '../converters/browser';

Since the package is "type": "module", these .d.ts files are interpreted as ESM, where node16/nodenext requires ./engine.js. In @embedpdf/engines 2.15.0 this affects 45 of the 69 published .d.ts files; @embedpdf/models 2.15.0 has the same problem (10 of 21 files). @embedpdf/pdfium is fine, since its index.d.ts is a single rolled-up file.

Lingua principale
TypeScript
Stelle
4.5k
Fork
317
Merge medio
10h 16m
PR unite (30g)
174

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 embedpdf/embed-pdf-viewer

Tutte le issue di embedpdf/embed-pdf-viewer

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.