Skip to content

feat(@nestjs/graphql): add conditional exports for browser shim#3943

Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:feat/package-exports-shim
Apr 21, 2026
Merged

feat(@nestjs/graphql): add conditional exports for browser shim#3943
kamilmysliwiec merged 1 commit intonestjs:masterfrom
yogeshwaran-c:feat/package-exports-shim

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

PR Checklist

  • The commit message follows our guidelines
  • Tests for the changes have been added (n/a for package.json change; exports verified manually via require.resolve + conditions)
  • Docs have been added / updated (n/a for package.json metadata)

Issue

Closes #3468

What is the new behavior?

Adds a proper "exports" map (plus matching top-level "browser" / "react-native" fields for legacy tooling) to @nestjs/graphql's package.json so the browser shim is picked up automatically, without consumers having to configure webpack/Metro/Vite aliases or resolver overrides.

Conditional resolution for the main entry (@nestjs/graphql):

  • types -> ./dist/index.d.ts
  • browser -> ./dist/extra/graphql-model-shim.js
  • react-native -> ./dist/extra/graphql-model-shim.js
  • node (nested) -> ./dist/index.js (types/require/import/default)
  • require / import -> ./dist/index.js
  • default -> ./dist/extra/graphql-model-shim.js (safe fallback for non-Node environments)

Additional subpaths are preserved for back-compat:

  • @nestjs/graphql/plugin -> ./plugin.js (with proper types pointing at ./dist/plugin/index.d.ts)
  • @nestjs/graphql/package.json -> explicit passthrough
  • @nestjs/graphql/* -> wildcard passthrough so existing deep imports such as @nestjs/graphql/dist/extra/graphql-model-shim.js continue to work

The existing main / types fields are kept to preserve compatibility with older tooling that does not understand exports. The shim's documentation comment is also updated to describe the new automatic behavior while keeping the legacy webpack-alias recipe for anyone on older setups.

Resolution verified locally via node --conditions=browser -e "require.resolve('@nestjs/graphql')" (resolves to the shim) and default node -e "require.resolve('@nestjs/graphql')" (resolves to dist/index.js). yarn build passes across all packages (graphql, apollo, mercurius).

@kamilmysliwiec kamilmysliwiec merged commit 6484358 into nestjs:master Apr 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use package exports for shim

2 participants