feat(@nestjs/graphql): add conditional exports for browser shim#3943
Merged
kamilmysliwiec merged 1 commit intonestjs:masterfrom Apr 21, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
require.resolve+ conditions)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'spackage.jsonso 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.tsbrowser->./dist/extra/graphql-model-shim.jsreact-native->./dist/extra/graphql-model-shim.jsnode(nested) ->./dist/index.js(types/require/import/default)require/import->./dist/index.jsdefault->./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.jscontinue to workThe existing
main/typesfields are kept to preserve compatibility with older tooling that does not understandexports. 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 defaultnode -e "require.resolve('@nestjs/graphql')"(resolves todist/index.js).yarn buildpasses across all packages (graphql,apollo,mercurius).