Open-Source Wikis

/

Next.js

/

Crates

/

next-core

vercel/next.js

next-core

Purpose

next-core is the largest non-Turbopack Rust crate. It owns the rules that translate Next.js configuration into Turbopack module options: which loaders run, which import maps apply per layer, how routes get bundled into entries, and what the App Router and Pages Router each look like as a Turbopack input.

Source: crates/next-core/src/. Heaviest files: next_config.rs (80 KB), next_import_map.rs (68 KB), app_structure.rs (70 KB), segment_config.rs (50 KB).

What it does

graph TD
    UserConfig[next.config.js] --> Bridge[next-api<br/>JS bridge]
    Bridge --> NextCore[next-core]
    NextCore --> ImportMap[Per-layer import maps]
    NextCore --> ModuleOptions[Module options<br/>per layer / runtime]
    NextCore --> AppStructure[App router structure]
    NextCore --> PagesStructure[Pages router structure]
    NextCore --> Manifests[Manifest emitters]
    ImportMap --> Tp[turbopack-core]
    ModuleOptions --> Tp

next-core doesn't bundle code itself — that's turbopack-core's job. It produces the inputs Turbopack needs to bundle a Next.js project correctly.

Major modules

next_config.rs (80 KB)

The Rust mirror of next.config.js. Reads the JSON-serialized config from the JS side, validates it, and exposes typed accessors (image domains, experimental flags, redirects, rewrites, headers, etc.) to the rest of next-core.

Critical role: this is where the framework decides what react-server-dom-webpack aliases to in Turbopack builds (the answer: react-server-dom-turbopack).

next_import_map.rs (68 KB)

Builds the import map for each layer (server, client, edge, react-server, route handler) and runtime mode (dev / build). The import map decides how react, react-dom, react-server-dom-*, and the framework's own internals resolve. It's the Rust equivalent of the JS create-compiler-aliases.ts.

app_structure.rs (70 KB)

Walks the user's app/ directory and produces a strongly-typed tree of segments, layouts, pages, error boundaries, loading boundaries, route handlers, default pages, and metadata files. Used by next-api/src/app.rs to plan App Router entries.

pages_structure.rs (16 KB)

The Pages Router equivalent of app_structure.rs. Produces a tree of pages/ files including the special ones (_app, _document, _error, 404, 500).

segment_config.rs (50 KB)

Reads per-page segment config from exported declarations (export const runtime = 'edge', export const dynamic = 'force-dynamic', etc.) using static analysis and propagates the values along the segment tree.

Subdirectories

Directory What
next_app/ App Router-specific entry generation
next_pages/ Pages Router-specific entry generation
next_client/ Client-side entry generation
next_client_reference/ Client component reference manifest generation
next_server/ Server-side entry generation
next_server_component/ Server component handling
next_dynamic/ next/dynamic support
next_edge/ Edge-runtime entry config
next_font/ next/font resolution and CSS injection
next_image/ Image asset handling
next_manifests/ Manifest types written to .next/
next_root_params/ Root params for typed routes
next_server_utility/ Server utilities exposed to the runtime
next_shared/ Code shared across runtimes

Telemetry

next_telemetry.rs (small) collects anonymized info about the Turbopack build (which features were used, build duration). Forwarded back to the JS side via the napi bridge and ultimately to Vercel's telemetry endpoint (subject to user opt-out).

Tracing presets

tracing_presets.rs declares the canned tracing-subscriber filter sets used for NEXT_TURBOPACK_TRACING=* environment variable values. The presets correspond to verbosity levels.

URL node and util

  • url_node.rs (24 KB) — A URL pattern data structure used for route matching at compile time.
  • util.rs (20 KB) — Path manipulation, glob expansion, hash-based cache keys.

Embed JS

embed_js.rs is a tiny helper for embedding JavaScript snippets (the framework's runtime entry shims, source-map fetchers) directly into the binary as include_str!-loaded constants.

Integration points

  • Consumed by crates/next-api which exposes the public crate surface.
  • Calls into turbopack-core, turbopack-ecmascript, turbopack-css, and other Turbopack crates.
  • The next-custom-transforms SWC visitors are registered into the Turbopack module options produced here.

Entry points for modification

  • To add a new config option: edit next_config.rs (validation) and the relevant downstream module.
  • To change how a layer's import map looks: next_import_map.rs.
  • To recognize a new file in the app/ directory: app_structure.rs.
  • To support a new segment-config field: segment_config.rs.

Key source files

File Purpose
crates/next-core/src/lib.rs Public crate entry
crates/next-core/src/next_config.rs Rust mirror of next.config.js
crates/next-core/src/next_import_map.rs Per-layer import maps
crates/next-core/src/app_structure.rs App Router segment tree
crates/next-core/src/pages_structure.rs Pages Router structure
crates/next-core/src/segment_config.rs Per-segment config inference
crates/next-core/src/transform_options.rs Compiler transform plumbing
crates/next-core/src/util.rs Path / glob / hash helpers

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

next-core – Next.js wiki | Factory