Skip to content

Conversation

@d-winter
Copy link
Contributor

Summary

  • Adds typesVersions field to package.json to support legacy TypeScript configurations
  • Fixes subpath imports (/react, /core) for users with moduleResolution: "node"

Problem

Users with older TypeScript setups reported needing to change their tsconfig.json to moduleResolution: "bundler" to use this SDK. This broke other imports in their projects.

The root cause: TypeScript's moduleResolution: "node" doesn't read the exports field in package.json, so it couldn't resolve types for subpath imports like @hygraph/preview-sdk/react.

Solution

Added typesVersions as a fallback for legacy TypeScript resolution:

"typesVersions": {
  "*": {
    "react": ["./dist/react/index.d.ts"],
    "core": ["./dist/core/index.d.ts"]
  }
}

This is safe because TypeScript prioritizes exports over typesVersions when both are present - modern setups are unaffected.

Test Plan

  • Verified legacy setup (moduleResolution: "node") fails without fix
  • Verified legacy setup works with fix
  • Verified modern setup (moduleResolution: "bundler") works before fix
  • Verified modern setup still works after fix
  • Verified SDK's own type-check passes

Users with moduleResolution: "node" in their tsconfig couldn't import from subpaths like @hygraph/preview-sdk/react because TypeScript's legacy resolution doesn't read the exports field.

Adding typesVersions provides a fallback for older setups while maintaining full compatibility with modern moduleResolution settings (bundler, node16, nodenext).
@d-winter d-winter requested a review from a team as a code owner December 12, 2025 09:43
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.

2 participants