nextjs - ✅(Solved) Fix Turbopack fails to resolve node:worker_threads Worker entries created with new URL(..., import.meta.url) [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#93427Fetched 2026-05-03 04:37:46
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1issue_type_added ×1

Fix Action

Fixed

PR fix notes

PR #93432: Fix Turbopack worker_threads URL resolution

Description (problem / solution / changelog)

Fixes #93427

What?

This fixes Turbopack's handling of Node.js worker_threads entries created with a URL object:

new Worker(new URL('./worker.ts', import.meta.url))

Turbopack was resolving this form with the same project-root context used for string/path worker entries. That makes relative URL worker entries fail when the relative URL should be resolved from the module that constructs it.

This PR keeps the existing behavior for string/path Node.js workers, but resolves relative URL worker entries from the module that creates the URL.

Why?

The issue reports a regression where this pattern worked in [email protected], but fails in [email protected] and [email protected]:

new Worker(new URL('../../worker-entry.mjs', import.meta.url))
new Worker(new URL('../../worker-entry.mts', import.meta.url))

The failure happens before the app can build because Turbopack tries to resolve the relative worker entry from the wrong context:

Module not found: Can't resolve '../../worker-entry.mjs'
Module not found: Can't resolve '../../worker-entry.mts'

Node.js documents Worker's filename argument as accepting either a string path or a WHATWG URL object. Relative string paths are resolved relative to the current working directory. By contrast, new URL(relative, import.meta.url) constructs a URL by resolving the relative specifier against the importing module's URL.

webpack also documents new Worker(new URL("./worker.js", import.meta.url)) as the supported Node.js worker_threads syntax. Matching that documented pattern avoids treating URL-object workers as if they were string-path workers.

How?

In turbopack-ecmascript worker reference analysis:

  • Detect relative JsValue::Url entries passed to the Node.js Worker constructor.
  • Use the importing module's parent directory as the resolution context for those URL entries.
  • Keep the existing traced project directory context for string/path worker entries and other Node.js worker forms.

This keeps the fix scoped to the URL-object case from the issue while preserving the existing behavior for string-path workers.

Tests

Added an e2e regression test to the existing Turbopack-specific node-worker-threads suite:

test/e2e/app-dir/node-worker-threads

The new test covers a Route Handler that creates a worker with:

new Worker(new URL('../../worker-dir/url-worker.ts', import.meta.url))

Verified locally:

cargo fmt --check --package turbopack-ecmascript
cargo check --package turbopack-ecmascript
pnpm build-all
pnpm test-dev-turbo test/e2e/app-dir/node-worker-threads/node-worker-threads.test.ts
pnpm test-start-turbo test/e2e/app-dir/node-worker-threads/node-worker-threads.test.ts
<!-- NEXT_JS_LLM_PR -->

Changed files

  • test/e2e/app-dir/node-worker-threads/app/api/url-worker-test/route.ts (added, +42/-0)
  • test/e2e/app-dir/node-worker-threads/app/worker-dir/url-worker.ts (added, +9/-0)
  • test/e2e/app-dir/node-worker-threads/node-worker-threads.test.ts (modified, +8/-0)
  • turbopack/crates/turbopack-ecmascript/src/references/mod.rs (modified, +11/-2)

Code Example

git clone https://github.com/publictheta/next-worker-url-repro.git
   cd next-worker-url-repro
   pnpm install

---

pnpm repro

---

apps/next-16-1 build:Next.js 16.1.7 (Turbopack)
   apps/next-16-1 build:Compiled successfully
   apps/next-16-1 build: Done

   apps/next-16-2 build:Next.js 16.2.4 (Turbopack)
   apps/next-16-2 build: Module not found: Can't resolve '../../worker-entry.mjs'
   apps/next-16-2 build: Module not found: Can't resolve '../../worker-entry.mts'
   apps/next-16-2 build: Failed

   apps/next-canary build:Next.js 16.3.0-canary.8 (Turbopack)
   apps/next-canary build: Module not found: Can't resolve '../../worker-entry.mjs'
   apps/next-canary build: Module not found: Can't resolve '../../worker-entry.mts'
   apps/next-canary build: Failed

---

new Worker(new URL("../../worker-entry.mjs", import.meta.url))
new Worker(new URL("../../worker-entry.mts", import.meta.url))

---

Module not found: Can't resolve '../../worker-entry.mjs'
Module not found: Can't resolve '../../worker-entry.mts'

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:32:59 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.5.0
  npm: 11.12.1
  Yarn: N/A
  pnpm: 10.33.0
Relevant Packages:
  next: 16.2.4 // Latest available version is detected (16.2.4).
  eslint-config-next: N/A
  react: 19.2.5
  react-dom: 19.2.5
  typescript: N/A
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/publictheta/next-worker-url-repro

To Reproduce

  1. Clone and install the reproduction:

    git clone https://github.com/publictheta/next-worker-url-repro.git
    cd next-worker-url-repro
    pnpm install
  2. Run the build comparison:

    pnpm repro
  3. Output:

    apps/next-16-1 build: ▲ Next.js 16.1.7 (Turbopack)
    apps/next-16-1 build: ✓ Compiled successfully
    apps/next-16-1 build: Done
    
    apps/next-16-2 build: ▲ Next.js 16.2.4 (Turbopack)
    apps/next-16-2 build: Module not found: Can't resolve '../../worker-entry.mjs'
    apps/next-16-2 build: Module not found: Can't resolve '../../worker-entry.mts'
    apps/next-16-2 build: Failed
    
    apps/next-canary build: ▲ Next.js 16.3.0-canary.8 (Turbopack)
    apps/next-canary build: Module not found: Can't resolve '../../worker-entry.mjs'
    apps/next-canary build: Module not found: Can't resolve '../../worker-entry.mts'
    apps/next-canary build: Failed

Current vs. Expected behavior

The reproduction creates Node.js workers from a Route Handler using URL objects:

new Worker(new URL("../../worker-entry.mjs", import.meta.url))
new Worker(new URL("../../worker-entry.mts", import.meta.url))

node:worker_threads accepts a URL object as the Worker filename. In this form, ../../worker-entry.mjs should be resolved relative to the module containing import.meta.url, i.e. the Route Handler module.

Current behavior:

With [email protected] and [email protected], Turbopack tries to resolve the relative URL worker entry from the wrong context and fails before the app can build:

Module not found: Can't resolve '../../worker-entry.mjs'
Module not found: Can't resolve '../../worker-entry.mts'

Expected behavior:

Turbopack should resolve URL object worker entries relative to the module that constructs the URL, while preserving the existing behavior for string/path Node.js workers.

This worked in [email protected], fails in [email protected], and is still present in [email protected].

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.4.0: Thu Mar 19 19:32:59 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8122
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 25.5.0
  npm: 11.12.1
  Yarn: N/A
  pnpm: 10.33.0
Relevant Packages:
  next: 16.2.4 // Latest available version is detected (16.2.4).
  eslint-config-next: N/A
  react: 19.2.5
  react-dom: 19.2.5
  typescript: N/A
Next.js Config:
  output: N/A

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

Module Resolution, Turbopack

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

next dev (local), next build (local)

Additional context

No response

extent analysis

TL;DR

The issue can be fixed by adjusting the way Turbopack resolves URL object worker entries to be relative to the module constructing the URL.

Guidance

  • Verify that the import.meta.url is correctly resolving to the expected module URL, ensuring the relative path to the worker entry is accurate.
  • Check if there are any configuration options in Turbopack or Next.js that can influence how URL objects are resolved for worker entries.
  • Consider using an absolute URL for the worker entry or adjusting the relative path to ensure it's correctly resolved from the context of the Route Handler module.
  • Review the differences in behavior between [email protected] and [email protected] to identify any changes that might have introduced this issue.

Example

No specific code example can be provided without further details, but ensuring the correct resolution of import.meta.url and the relative path to the worker entry is key.

Notes

The issue seems to be related to how Turbopack resolves URLs for worker entries in Next.js versions 16.2.4 and later. The exact fix might depend on specifics of the project setup and how Turbopack is configured.

Recommendation

Apply a workaround by adjusting the URL resolution for worker entries, possibly by using absolute URLs or ensuring the relative paths are correctly resolved from the module context, as the issue persists in the latest available version of Next.js.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - ✅(Solved) Fix Turbopack fails to resolve node:worker_threads Worker entries created with new URL(..., import.meta.url) [1 pull requests, 1 participants]