nextjs - ✅(Solved) Fix Turbopack can't use "export * as Foo" syntax, but webpack can [2 pull requests, 2 comments, 3 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#86714Fetched 2026-04-08 02:09:39
View on GitHub
Comments
2
Participants
3
Timeline
11
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2referenced ×2closed ×1

Error Message

❯ pnpm run build

[email protected] build /Users/matowang/Code/nextjs-turbopack-2025-12-02 next build

▲ Next.js 16.1.0-canary.10 (Turbopack)

Creating an optimized production build ... ✓ Compiled successfully in 1913.0ms ✓ Finished TypeScript in 1434.7ms
Collecting page data using 7 workers ..Error: Failed to collect configuration for / at ignore-listed frames { [cause]: Error: Module 53781 was instantiated because it was required from module 60168, but the module factory is not available. at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:711:15) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]runtime.js:228:20) at module evaluation (.next/server/chunks/ssr/[root-of-the-server]__f237040c..js:3:1124) at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20) at module evaluation (.next/server/chunks/ssr/f2898698..js:1:59) at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) }

Build error occurred Error: Failed to collect page data for / at ignore-listed frames { type: 'Error' }  ELIFECYCLE  Command failed with exit code 1.

Root Cause

Creating an optimized production build ... ✓ Compiled successfully in 1913.0ms ✓ Finished TypeScript in 1434.7ms
Collecting page data using 7 workers ..Error: Failed to collect configuration for / at ignore-listed frames { [cause]: Error: Module 53781 was instantiated because it was required from module 60168, but the module factory is not available. at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:711:15) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]runtime.js:228:20) at module evaluation (.next/server/chunks/ssr/[root-of-the-server]__f237040c..js:3:1124) at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20) at module evaluation (.next/server/chunks/ssr/f2898698..js:1:59) at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9) at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12) }

Fix Action

Fixed

PR fix notes

PR #86131: Turbopack: scope hoisting bug with reexport-self-star

Description (problem / solution / changelog)

Closes PACK-5850 Closes https://github.com/vercel/next.js/issues/86132 Closes #86714

The problem was that you get this with scope hoisting:

"index.js": () => {

// foo.js

// exports object read here
const self_import = turbopack_import("foo.js")

// exports object created here
__turbopack_esm__([...], "foo.js")

// index.js

....
}

without scope hoisting, that exports object is already initialized before the module factory runs

"foo.js": () => { // exports initialized here

const self_import = turbopack_import("foo.js")


__turbopack_esm__([....]);
}
....

so let's fix it by making it hoist the __turbopack_esm__ statement (just as we did before always) in the case of self-imports


This bug is actually very similar to https://github.com/vercel/next.js/pull/82827. It also executes data.js twice.

The problem is that if a module imports itself,

"[project]/input/data.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";

var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/input/data.js [test] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/input/data.js [test] (ecmascript)");
__turbopack_context__.s([
    "Data",
    0,
    __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__,
    "bar",
    ()=>__TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__["bar"],
    "foo",
    ()=>__TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__["foo"]
]);
}),

and with scope hoisting, the import("id") happens before the esm_export(..., "id"):

module.exports = [
"[project]/index.js [test] (ecmascript)", ((__turbopack_context__) => {
"use strict";

// MERGED MODULE: [project]/index.js [test] (ecmascript)
;
// MERGED MODULE: [project]/data.js [test] (ecmascript) <locals>
;
function foo() {
    return 'foo';
}
function bar() {
    return 'bar';
}
;
__turbopack_context__.s([
    "bar",
    ()=>bar,
    "foo",
    ()=>foo
], "[project]/data.js [test] (ecmascript) <locals>");
// MERGED MODULE: [project]/data.js [test] (ecmascript) <export * as Data>
;
// MERGED MODULE: [project]/data.js [test] (ecmascript)
;
var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/data.js [test] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/data.js [test] (ecmascript)");
__turbopack_context__.s([
    "Data",
    0,
    __TURBOPACK__imported__module__$5b$project$2f$input$2f$data$2e$js__$5b$test$5d$__$28$ecmascript$29$__,
    "bar",
    ()=>bar,
    "foo",
    ()=>foo
], "[project]/data.js [test] (ecmascript)");

Changed files

  • turbopack/crates/turbopack-core/src/module_graph/binding_usage_info.rs (modified, +10/-3)
  • turbopack/crates/turbopack-core/src/module_graph/mod.rs (modified, +65/-3)
  • turbopack/crates/turbopack-core/src/module_graph/module_batches.rs (modified, +4/-3)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/self-reexport-star/input/data.js (added, +9/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/self-reexport-star/input/index.js (added, +6/-0)
  • turbopack/crates/turbopack-tests/tests/execution/turbopack/exports/self-reexport-star/options.json (added, +3/-0)

Code Example

// /src/app/module-test.ts
export * as ModuleTest from "./module-test";

export function moduleTest() {
  return "moduleTest";
}

---

// /src/app/page.tsx
import { ModuleTest } from "./module-test";
export default function Home() {
  console.log(ModuleTest.moduleTest());
  return (
  // ...
  )
}

---

pnpm run build

---

❯ pnpm run build                                                                   

> nextjs-turbopack-2025-12-02@0.1.0 build /Users/matowang/Code/nextjs-turbopack-2025-12-02
> next build

Next.js 16.1.0-canary.10 (Turbopack)

  Creating an optimized production build ...
Compiled successfully in 1913.0ms
Finished TypeScript in 1434.7ms    
  Collecting page data using 7 workers  ..Error: Failed to collect configuration for /
    at ignore-listed frames {
  [cause]: Error: Module 53781 was instantiated because it was required from module 60168, but the module factory is not available.
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:711:15)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
      at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20)
      at module evaluation (.next/server/chunks/ssr/[root-of-the-server]__f237040c._.js:3:1124)
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
      at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20)
      at module evaluation (.next/server/chunks/ssr/_f2898698._.js:1:59)
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
}

> Build error occurred
Error: Failed to collect page data for /
    at ignore-listed frames {
  type: 'Error'
}
ELIFECYCLECommand failed with exit code 1.

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 16.1.0-canary.10 // Latest available version is detected (16.1.0-canary.10).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/matowang/nextjs-turbopack-2025-12-02

To Reproduce

  1. Create module with export * as Foo syntax
// /src/app/module-test.ts
export * as ModuleTest from "./module-test";

export function moduleTest() {
  return "moduleTest";
}
  1. import it
// /src/app/page.tsx
import { ModuleTest } from "./module-test";
export default function Home() {
  console.log(ModuleTest.moduleTest());
  return (
  // ...
  )
}
  1. Build it
pnpm run build

Current vs. Expected behavior

Expected build to work, but the build fails.

❯ pnpm run build                                                                   

> [email protected] build /Users/matowang/Code/nextjs-turbopack-2025-12-02
> next build

▲ Next.js 16.1.0-canary.10 (Turbopack)

  Creating an optimized production build ...
✓ Compiled successfully in 1913.0ms
✓ Finished TypeScript in 1434.7ms    
  Collecting page data using 7 workers  ..Error: Failed to collect configuration for /
    at ignore-listed frames {
  [cause]: Error: Module 53781 was instantiated because it was required from module 60168, but the module factory is not available.
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:711:15)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
      at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20)
      at module evaluation (.next/server/chunks/ssr/[root-of-the-server]__f237040c._.js:3:1124)
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
      at Context.esmImport [as i] (.next/server/chunks/ssr/[turbopack]_runtime.js:228:20)
      at module evaluation (.next/server/chunks/ssr/_f2898698._.js:1:59)
      at instantiateModule (.next/server/chunks/ssr/[turbopack]_runtime.js:719:9)
      at getOrInstantiateModuleFromParent (.next/server/chunks/ssr/[turbopack]_runtime.js:742:12)
}

> Build error occurred
Error: Failed to collect page data for /
    at ignore-listed frames {
  type: 'Error'
}
 ELIFECYCLE  Command failed with exit code 1.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 16.1.0-canary.10 // Latest available version is detected (16.1.0-canary.10).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.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

I ran pnpm run build both locally and on vercel. They both fail with the same logs.

Using pnpm run build --webpack works as expected.

extent analysis

TL;DR

The build failure is likely due to an issue with Turbopack in Next.js 16.1.0-canary.10, and using the --webpack flag resolves the issue.

Guidance

  • The error message suggests a problem with module instantiation, which may be related to the export * as Foo syntax.
  • Try removing or modifying the export * as ModuleTest line to see if it resolves the issue.
  • Since using pnpm run build --webpack works, it may indicate a compatibility issue with Turbopack.
  • Verify that the issue persists with the latest version of Next.js and Turbopack.

Example

No code example is provided as the issue seems to be related to the build process and module syntax.

Notes

The issue may be specific to the combination of Next.js 16.1.0-canary.10 and Turbopack. Further investigation is needed to determine the root cause.

Recommendation

Apply workaround: use pnpm run build --webpack to build the project until the issue with Turbopack is resolved.

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