Skip to content

Conversation

@rituzangle
Copy link

This PR updates the exports field in package.json to resolve a broken import path that currently triggers fallback resolution in Node environments.

Problem:
Replaced broken "import": "./index.js" with correct "import": "./esm.mjs" to match published files and avoid fallback resolution. This causes Node to fall back to file-based resolution, resulting in warnings like:

Code:
The resolution for "use-latest-callback" defined in "exports" is ./esm.mjs, however this file does not exist. Falling back to file-based resolution.
This fallback behavior is fragile and breaks compatibility with bundlers like Metro (React Native) and Vite, which rely on strict exports resolution.

Fix
Replaced the broken "import" path with a valid conditional exports block in package.json:

json
"exports": {
  ".": {
    "types": "./lib/src/index.d.ts",
    "import": "./esm.mjs",
    "require": "./lib/src/index.js",
    "default": "./lib/src/index.js"
  }
}

This ensures:

  • Compatibility with ESM and CommonJS environments
  • Proper type resolution for TypeScript consumers
  • No fallback warnings during install or runtime
  • "import" resolves to the actual ESM file you’re publishing
  • "require" and "default" resolve to the CommonJS fallback
  • TypeScript gets proper type hints

Tested With:

  • Node.js (v18+)
  • Metro bundler (React Native)
  • Vite (React web)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant