-
-
Notifications
You must be signed in to change notification settings - Fork 361
Description
- 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.json → exports["."].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):
- In
src/fxp.d.ts, use a NodeNext-valid specifier, e.g.from './pem.js'(TypeScript resolves this topem.d.ts). - Or point
exports["."].import.typesat declaration files that already satisfy NodeNext rules (e.g. generated.d.tswith correct extensions), if you prefer not to hand-editsrc/*.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.:
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
tscshould succeed withmoduleResolution:"NodeNext"andskipLibCheck:falsewhen resolving types forfast-xml-parser@5.5.8(and future patch releases), without requiring consumers to patchnode_modulesor enableskipLibCheck.
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.