New advertisers: 50% off your first month with code FIRSTMONTHSee slots
vercel avatar

Dce Edge

Conditional require() and edge-runtime guardrails for webpack DCE in Next.js builds.

skills.sh installs
842
GitHub stars
143.6K
last updated
May 16, 2026
View on GitHub

What it does

  • Covers DCE-safe require() patterns: if/else branching, TypeScript definite assignment, and the NEXT_RUNTIME versus real feature flag distinction
  • Includes a compile-time switcher pattern for node and web variants, exemplified by stream-ops.ts and debug-channel-server.ts
  • Enforces forcing feature flags to false for edge builds in define-env.ts, so node:stream imports never resolve
  • Designed for editing define-env-plugin.ts, app-page.ts, and stream-utils when changing edge or Node-only code paths

Install

$ npx -y skills add vercel/next.js --skill dce-edge -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

DCE + Edge

Use this skill when changing conditional require() paths, Node-only imports, or edge/runtime branching.

DCE-Safe require() Pattern

Webpack only DCEs a require() when it sits inside the dead branch of an if/else whose condition DefinePlugin can evaluate at compile time.

// CORRECT - webpack can eliminate the dead branch
if (process.env.__NEXT_USE_NODE_STREAMS) {
  require('node:stream')
} else {
  // web path
}

What does NOT work:

  • Early-return/throw guards: webpack doesn't do control-flow analysis for throws/returns, so the require() is still traced.
  • Bare if without else: works for inline node:* specifiers but NOT for require('./some-module') that pulls a new file into the module graph.

Always test edge changes with pnpm test-start-webpack on test/e2e/app-dir/app/standalone.test.ts (has edge routes), not with NEXT_SKIP_ISOLATE=1 which skips the full webpack compilation.

TypeScript + DCE Interaction

Details

Repository
github.com/vercel/next.js
Categories
Frontend & UI Code, Backend & APIs
First seen
Apr 16, 2026

More from vercel/next.js

All 14

Similar to Dce Edge

More Frontend & UI Code