Skip to content

3.5.0+ cannot be bundled against the WebGL build of three (Next.js / Turbopack + webpack): WebGPU-only symbols read as static members of the three namespace #350

Open

Description

@TristanLecallierABIME

Describe the bug 📝

Since @thatopen/[email protected], the published ESM reads WebGPU-only three symbols (TSL, MRTNode, OutputStructNode, WebGPURenderer, NodeMaterial) as static named members of import * as THREE from "three".

Those symbols exist only in three/webgpu (build/three.webgpu.js), never in the default three entry (build/three.module.js). The call sites are correctly guarded at runtime, but bundlers that enforce ESM named-export correctness reject the module graph before any guard can run, so the build fails outright.

This makes the WebGL configuration — which this package explicitly supports (peerDependencies: { "three": ">=0.182.0" }, no webgpu condition) — impossible to build in Next.js. It is a regression: the 3.4.x line builds clean.

Not Turbopack-specific. Both bundlers fail:

  • Turbopack (Next.js 16 default): Export MRTNode doesn't exist in target module
  • Webpack: 'Node' is not exported from 'three' — this is the default next build on Next.js 15.x, so Next 15 users are affected too, not only Turbopack users.

Reproduction ▶️

No response

Steps to reproduce 🔢

Environment :

@thatopen/fragments : 3.6.0 (also 3.5.0, 3.5.1)
@thatopen/components : 3.6.0
@thatopen/components-front : 3.6.0
three : 0.184.0
Next.js : 16.4.4 (latest stable), 16.5.0-canary.37, and 15.5.28 — all affected
Node / pnpm : 22.x / 10.28

package.json:

{
  "dependencies": {
    "@thatopen/components": "3.6.0",
    "@thatopen/components-front": "3.6.0",
    "@thatopen/fragments": "3.6.0",
    "next": "16.4.4",
    "react": "19.2.0",
    "react-dom": "19.2.0",
    "three": "0.184.0",
    "web-ifc": "0.0.77"
  }
}

A single client component is enough — no model needs to be loaded, because the failure is at
link time:

"use client";
import * as OBC from "@thatopen/components";

export default function Viewer() {
  return <div>{typeof OBC.Components}</div>;
}
next build            # Turbopack
next build --webpack  # webpack
./node_modules/@thatopen/fragments/dist/FragmentsModels/src/model/material-manager.mjs:1:1
Export MRTNode doesn't exist in target module
> 1 | import * as THREE from "three";
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The export MRTNode was not found in module
[project]/node_modules/three/build/three.module.js [app-client] (ecmascript).
Did you mean to import ClampToEdgeWrapping?
All exports of the module are statically known (It doesn't have dynamic exports).
So it's known statically that the requested export doesn't exist.

Turbopack fails fast, so fixing one symbol just reveals the next.

Root cause

The feature-detection intent is right; the access pattern is what is not portable. ESM makes a
missing named export statically detectable, and the bundler validates the namespace member
access at link time — the typeof / ?. guards never get a chance to run.

dist/FragmentsModels/src/model/material-manager.mjs:

const isWebGPUBuild = () => typeof THREE.WebGPURenderer === "function";   // line 11
// ...
const tsl = THREE.TSL;                                                    // line 433
if (!tsl?.output || !THREE.MRTNode) return;                               // line 434

dist/FragmentsModels/src/model/target-aware-mrt.mjs:

const { MRTNode, OutputStructNode } = THREE;                              // line 5

dist/FragmentsModels/src/model/shell-layer-nodes.mjs:

const tsl = THREE.TSL;
const canRun = typeof THREE.WebGPURenderer === "function" && tsl && ...

dist/FragmentsModels/src/lod/lod-node-material.mjs:

const NodeMaterialBase = THREE.NodeMaterial ?? class { ... };             // line 3

Verified against [email protected]: all five symbols are absent from three/src/Three.js
(441 exports, identical surface to build/three.module.js) and present in
build/three.webgpu.js.

Aliasing three → three/webgpu is not a viable workaround: three/webgpu does not
export WebGLRenderer, and it would flip isWebGPUBuild() to true, silently switching the
library into the TSL/node-material path while the app still renders with WebGL.

Version bisect

Measured under both bundlers (Turbopack and webpack), no workarounds applied:

Stack Turbopack webpack
components 3.4.9 / components-front 3.4.5 / fragments 3.4.8 ✅ compiles clean ✅ compiles clean
components 3.5.0 / components-front 3.5.0 / fragments 3.5.1 ❌ fails ❌ fails
components 3.6.0 / components-front 3.6.0 / fragments 3.6.0 ❌ fails ❌ fails

THREE.{TSL,MRTNode,WebGPURenderer,NodeMaterial} first appear in dist at 3.5.0; no
occurrences in 3.2.0, 3.3.0, 3.4.0, 3.4.4 or 3.4.8.

Full symbol list

Reported by Turbopack, from fragments: MRTNode, TSL, WebGPURenderer, NodeMaterial.
Found by static scan but tree-shaken in a minimal app, so they surface only once more code
paths are reached: OutputStructNode.

(@thatopen/components and @thatopen/components-front 3.5.0+ have the same pattern plus
PointsNodeMaterial, StorageTexture, RenderPipeline, NodeUpdateType, BlendMode,
Node, PassNode — filed separately against engine_components.)

Suggested fixes

Any of these keeps the single-package, runtime-detected design intact:

  1. Read through a non-static reference, so there is no namespace member to validate:

    const T = /** @type {any} */ (globalThis).__THREE__ ?? THREE;

    or more simply, resolve the webgpu namespace once via await import("three/webgpu")
    inside the webgpu branch, and never name those symbols on the three namespace.

  2. Isolate the WebGPU code behind a subpath export (@thatopen/fragments/webgpu), so a
    WebGL consumer never links the modules that reference three/webgpu symbols. This matches
    the webgpu/ folder already shipped in components-front.

  3. Document a required bundler alias for WebGL consumers, as
    components-front/webgpu/webgl-addons-stub.mjs already does for the inverse case.

Current workaround (for anyone hitting this)

A shim that re-exports the WebGL build and declares the WebGPU-only symbols as undefined —
which is exactly what the library's guards expect to find:

// three-webgl-shim.mjs
export * from "three/src/Three.js"; // same 441 exports as build/three.module.js

export const TSL = undefined;
export const MRTNode = undefined;
export const OutputStructNode = undefined;
export const WebGPURenderer = undefined;
export const NodeMaterial = undefined;
export const MeshBasicNodeMaterial = undefined;
export const PointsNodeMaterial = undefined;
export const BlendMode = undefined;
export const Node = undefined;
export const NodeUpdateType = undefined;
export const RenderPipeline = undefined;
export const StorageTexture = undefined;
export const PassNode = undefined;
// next.config.mjs
turbopack: { resolveAlias: { three: "./three-webgl-shim.mjs" } }

Verified on Next 16.4.4 and 16.5.0-canary.37, Turbopack and webpack, dev and production:
builds clean, isWebGPUBuild() correctly stays false, a renderer constructed inside
@thatopen/components still passes instanceof against the app's THREE.WebGLRenderer
(single three instance), and a real render pass runs with no console errors.

System Info 💻

Next.js / Turbopack + webpack

Used Package Manager 📦

pnpm

Error Trace/Logs 📃

No response

Validations ✅

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Make sure this is a repository issue and not a framework-specific issue. For example, if it's a THREE.js related bug, it should likely be reported to mrdoob/threejs instead.
  • Check that this is a concrete bug. For Q&A join our Community.
  • The provided reproduction is a minimal reproducible example of the bug.

Activity

  1. added
    bug
    on Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions