Skip to content

TS2834: fxp.d.ts imports './pem' without extension under NodeNext moduleResolution #808

@tomquist

Description

@tomquist
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool? (not applicable — TypeScript resolution issue, not runtime parse output)
  • Have you checked the docs for helpful APIs and examples?

Description

With moduleResolution set to "node16" or "nodenext" (TypeScript 5.x), the package’s published ESM types entry (package.jsonexports["."].import.types./src/fxp.d.ts) fail to type-check because src/fxp.d.ts uses a relative import without a .js extension:

import type { Expression, ReadonlyMatcher } from './pem';

TypeScript reports TS2834 (“Relative import paths need explicit file extensions in ECMAScript imports when --moduleResolution is node16 or nodenext”).

This affects consumers that type-check dependencies (e.g. skipLibCheck: false) and pull types through fast-xml-parser as a transitive dependency (for example via AWS SDK for JavaScript v3’s @aws-sdk/xml-builder, which depends on fast-xml-parser — see aws-sdk-js-v3 v3.1014.0 changelog mentioning the xml-builder / fast-xml-parser bump).

Suggested fix (either or both):

  1. In src/fxp.d.ts, use a NodeNext-valid specifier, e.g. from './pem.js' (TypeScript resolves this to pem.d.ts).
  2. Or point exports["."].import.types at declaration files that already satisfy NodeNext rules (e.g. generated .d.ts with correct extensions), if you prefer not to hand-edit src/*.d.ts.

Input

TypeScript project using NodeNext resolution (minimal tsconfig.json excerpt):

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "skipLibCheck": false
  }
}

Code

Any dependency path that causes the compiler to load the ESM types for the main entry, e.g.:

// package.json (consumer)
{
  "dependencies": {
    "fast-xml-parser": "5.5.8"
  }
}

Then run the compiler; no application import of fast-xml-parser is required if another package’s types pull in fxp.d.ts (e.g. via @aws-sdk/xml-builder).

Alternatively, a minimal direct repro:

// Any .ts file
import type { XMLParser } from "fast-xml-parser";
type _ = XMLParser;

Output

node_modules/fast-xml-parser/src/fxp.d.ts(1,50): 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.

expected data

  • tsc should succeed with moduleResolution: "NodeNext" and skipLibCheck: false when resolving types for fast-xml-parser@5.5.8 (and future patch releases), without requiring consumers to patch node_modules or enable skipLibCheck.

Environment: fast-xml-parser@5.5.8, TypeScript 5.9 (or any 5.x with TS2834 for extensionless relative imports in .d.ts).


Would you like to work on this issue?

  • Yes
  • No

Bookmark this repository for further updates. Visit SoloThought to know about recent features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions