Skip to content

Unable to resolve types with moduleResolution set to node16 #7

@rexxars

Description

@rexxars

It looks like when using TypeScript with the moduleResolution flag set to node16 (and using type: 'module' in the apps package.json), it correctly resolves the import to the index.mjs file using the exports declaration, but it is not able to find the type definitions.

This seems to be solved by adding a types entry to the exports, pointing to the .d.ts:

{
  "exports": {
    ".": {
      "node": {
        "types": "./lib/index.d.ts", // <--- this one
        "require": "./lib/index.cjs",
        "import": "./dist/index.mjs"
      },
      // ...
    }
  }
}

This is documented in the ES Modules in Node.js section of the TypeScript handbook.

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