Skip to content

Type resolve error in Node ESM mode #29

Closed
@otakustay

Description

@otakustay

For TS project having "moduleResolution": "NodeNext" in tsconfig.json and "type": "module" in package.json, TypeScript can't resolve to correct types.

import parseGitDiffExport from 'parse-git-diff';

// This expression is not callable.
//  Type 'typeof import("node_modules/parse-git-diff/build/types/index")' has no call signatures.ts(2349)
parseGitDiffExport(diff);

This is how TypeScript's NodeNext mode interacts with CommonJS packages, seems the only fix is to put index.d.ts in both build/cjs and build/mjs and then remove "types" key in exports field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions