vercel / vercel/next.js

Turbopack crashes with SWC plugins when using absolute paths in swcPlugins configuration

Open
#78,156 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

linear: turbopack Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/jantimon/yak-n-run

To Reproduce
  1. Create a Next.js project with a custom SWC plugin
  2. Configure the SWC plugin using require.resolve() which returns an absolute path
    a. clone https://github.com/jantimon/yak-n-run
    b. (alternative): use require resolve directly
nextConfig.experimental.swcPlugins.push([
  require.resolve("some-swc-plugin"),
  {
    // ...
  },
])
  1. Run next build --turbopack
Current vs. Expected behavior

Current behavior:
Turbopack immediately crashes with an error message indicating that the plugin path does not exist:

./
Module not found: Can't resolve './path/to/yak-n-run/node_modules/yak-swc/target/wasm32-wasip1/release/yak_swc.wasm'
server relative imports are not implemented yet. Please try an import relative to the file you are importing from.

./
Module not found: Can't resolve '/path/to/yak-n-run/node_modules/yak-swc/target/wasm32-wasip1/release/yak_swc.wasm'


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


    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)
    at <unknown> (https://nextjs.org/docs/messages/module-not-found)

The error message shows the path with a leading dot (e.g., ./foo/bar/yak-n-run/node_modules/yak-swc/target/wasm32-wasip1/release/yak_swc.wasm) - so I guess it is trying to resolve it relatively

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10
Binaries:
  Node: 20.18.2
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 10.2.0
Relevant Packages:
  next: 15.3.1-canary.7 // Latest available version is detected (15.3.1-canary.7).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
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

✅ Works correctly with webpack (without --turbopack)

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 by reproducing the failure in the linked yak-n-run project using next build --turbopack and the swcPlugins configuration with require.resolve(). Trace how next.config plugin paths are passed into Turbopack and compare the behavior with webpack. Done means an absolute SWC plugin path builds successfully with Turbopack and the failure is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.