Skip to content

Missing "types" in package.json "exports" field breaks TypeScript with moduleResolution: "bundler" #325

Closed

Description

@evgeniiPerov

When using @hcaptcha/react-hcaptcha@1.17.0 with TypeScript's moduleResolution: "bundler" (required for ESM projects), TypeScript cannot
resolve the type declarations.

Error

error TS7016: Could not find a declaration file for module '@hcaptcha/react-hcaptcha'.
'/node_modules/@hcaptcha/react-hcaptcha/dist/esm/index.js' implicitly has an 'any' type.
There are types at '/node_modules/@hcaptcha/react-hcaptcha/types/index.d.ts', but this result
could not be resolved when respecting package.json "exports".

Root Cause

The package.json has an exports field but doesn't include types entries:

"exports": {
  ".": {
    "import": "./dist/esm/index.js",
    "require": "./dist/index.js"
  }
}

When TypeScript uses moduleResolution: "bundler", it strictly respects the exports field and requires types to be explicitly declared.

Solution

Add types to the exports field:

"exports": {
  ".": {
    "types": "./types/index.d.ts",
    "import": "./dist/esm/index.js",
    "require": "./dist/index.js"
  },
  "./hooks": {
    "types": "./types/hooks/index.d.ts",
    "import": "./dist/esm/hooks/index.jsx",
    "require": "./dist/hooks/index.jsx"
  }
}

Note: The types condition must come first in each export entry.

Environment

- @hcaptcha/react-hcaptcha: 1.17.0
- TypeScript: 5.x
- moduleResolution: "bundler"

Related

- #247

Activity

  1. zoryana94 commented on Dec 9, 2025

    @zoryana94
    Contributor

    Hi @evgeniiPerov,
    Thank you a lot for notifying us!
    As you already have the solution outlined, we encourage you to contribute to the project with the PR created.
    We appreciate all the contributions!
    Alternatively, we'll handle it with the team.

    Best Regards,
    hCaptcha Dev Team

  2. zoryana94 commented on Dec 9, 2025

    @zoryana94
    Contributor

    @evgeniiPerov, thank you a lot for your contribution!
    Please also check if the issue is resolved in react-hcaptcha 1.17.1

  3. joao-imi commented on Dec 9, 2025

    @joao-imi
    Contributor

    Issue addressed in the commit: #326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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