dce-edge

Guard edge-runtime code paths and conditional imports in Next.js builds.

Updated Apr 7, 2026
One-click install
npx skills add https://github.com/villa1/backupshop --skill dce-edge-villa1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dce-edge
Source: https://github.com/villa1/backupshop/tree/main/.agents/skills/dce-edge
Command: npx skills add https://github.com/villa1/backupshop --skill dce-edge-villa1

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Edge-runtime development often requires careful orchestration of conditional imports and node-only modules to keep builds valid for both edge and web targets. This skill provides proven patterns to safely gate require() calls and guard environment-specific code.

Core Features & Use Cases

  • DCE-Safe import patterns: use conditional requires and DefinePlugin-friendly branches to allow webpack/turbopack to prune unused paths.
  • TypeScript safety and edge-vs-web gating: ensure definite assignment and correct imports depending on runtime.
  • Compile-time switchers: create a single switcher module that loads .node or .web variants based on environment.
  • Edge-runtime constraints awareness: guard node:* imports and environment-based flags to support edge routes.

Quick Start

Use this skill to implement edge-safe require patterns by wrapping Node imports with conditional guards so edge builds compile cleanly and web builds stay free of Node-only dependencies.

Frequently Asked Questions about dce-edge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely use require in Next.js edge runtime without breaking the build?

To safely use require in Next.js edge runtime, wrap Node.js imports with conditional guards and DefinePlugin-friendly branches so webpack or turbopack can prune unused paths during dead code elimination. This keeps edge builds valid while web builds stay free of Node-only dependencies.

What are DCE-safe require patterns in webpack for edge vs web environments?

DCE-safe require patterns use conditional imports and compile-time switchers to load .node or .web variants based on environment. This allows webpack and turbopack to prune unused code paths during dead code elimination, ensuring clean edge-runtime builds.

Why does my Next.js edge route fail when importing node-only modules?

Edge route builds fail importing node-only modules because the edge runtime restricts node:* imports. You need compile-time guards and environment-based flags to gate these requires, preventing Node dependencies from leaking into edge-runtime code paths.

Can I use a single switcher module to handle both edge and web imports in Next.js?

Yes, you can create a single compile-time switcher module that loads .node or .web variants based on the runtime environment. This pattern uses DCE-safe conditional requires to ensure correct imports depending on whether the target is edge or web.

How do I ensure TypeScript safety when gating edge-runtime code paths?

To ensure TypeScript safety when gating edge-runtime code paths, use definite assignment and compile-time switchers that conditionally import environment-specific modules. This provides type safety while maintaining DCE-safe branches for edge versus web targets.

What's the best way to guard environment-specific code for Next.js edge builds?

The best way to guard environment-specific code is using DefinePlugin-friendly conditional branches and DCE-safe require patterns. This approach gates node:* imports with environment-based flags, allowing bundlers to prune unused paths for clean edge builds.