vercel / vercel/next.js

Relay compiler configuration "exclude" option is not respected

Open
#69,890 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.5k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/mjfaga/nextjs-relay-swc-excludes

To Reproduce

Install dependencies and build:

yarn install
yarn build
Current vs. Expected behavior

Current Behavior

When adding a library (in the MVP, @stigg/react-sdk) that uses GraphQL under the hood, the relay compiler breaks consumption of that library and the app no longer properly builds.

 ± yarn build
yarn run v1.22.21
$ relay-compiler --validate && next build
[INFO] Querying files to compile...
[INFO] [default] compiling...
[INFO] [default] compiled documents: 0 reader, 0 normalization, 0 operation text
[INFO] Compilation completed.
[INFO] Done.
  ▲ Next.js 14.2.8

   Creating an optimized production build ...
Failed to compile.

./node_modules/@stigg/js-client-sdk/dist/index.js
Module not found: Can't resolve '/Users/markfaga/projects/nextjs-relay-swc-excludes/./__generated__/SlimSubscriptionFragmentV2.graphql.ts'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@stigg/react-sdk/dist/react-sdk.esm.js
./src/app/page.tsx

Expected Behavior

No errors because node_modules is excluded from being targeted during relay GraphQL compilation (see below for additional context).

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020
  Available memory (MB): 98304
  Available CPU cores: 12
Binaries:
  Node: 22.7.0
  npm: 10.8.2
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 14.2.8 // Latest available version is detected (14.2.8).
  eslint-config-next: 14.2.8
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

The current SWC relay compiler implementation only supports 3 key options:

  • src
  • language
  • artifact_directory

exclude is another critical option that is not currently supported. In the direct relay implementation, this is optional BUT ships with a default value of ["**/node_modules/**", "**/mocks/**", "**/generated/**"] to ensure things like packages in node_modules aren't targeted when they also happen to use GraphQL under the hood. In these cases, node_module source is recompiled, breaking those libraries.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with turbopack/crates/turbopack-ecmascript-plugins/src/transform/relay.rs and the linked reproduction repository. Run yarn install and yarn build there, then trace how Relay options are passed to the SWC implementation. Done means the exclude option is respected and the reproduction builds without recompiling the dependency's GraphQL sources.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
build-system, compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.