dce-edge
预览截图
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "dce-edge":https://skillpi.com/zh/skills/deepskill-01eed7a9139719c00ef756db063bbd2c0acdcffb5d2cde6d4edc4356d3977e31。安装前核对上游来源和版本:https://github.com/vercel/next.js。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
描述与边缘运行时约束兼容的 DCE 安全 require() 模式。适用于编写条件 require() 调用、保护仅限 Node.js 的导入(如 node:stream),或修改 define-env-plugin.ts、app-render、stream-utils 以适配边缘构建。涵盖 webpack DCE 对 if/else 分支的处理、TypeScript 明确赋值、NEXT_RUNTIME 与实际功能标志的区别,以及在 define-env.ts 中将标志强制设为 false 以适配边缘环境。元数据:internal: true。
介绍来源: third_party · vercel · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 更改条件时使用此技能 `require()` 路径, 仅节点导入,或边缘/运行时间分支.
- 适合谁
- 来源文档未说明。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 边缘路由不使用预编译的运行时间捆绑 。 由用户的网页包/Turbopack编译,所以 `define-env.ts` 控制DCE。 控制DCE。 大门的标志 `node:*` 必须强迫进口 `false` 边框结构 `define-env.ts` (单位:千美元) `isEdgeServer ? false : flagValue` ),否则网页包将试图解决 `node:stream` 失败。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: dce-edge
description: >
DCE-safe require() patterns and edge runtime constraints. Use when writing
conditional require() calls, guarding Node-only imports (node:stream etc.),
or editing define-env-plugin.ts / app-render / stream-utils for edge builds.
Covers if/else branching for webpack DCE, TypeScript definite assignment,
the NEXT_RUNTIME vs real feature flag distinction, and forcing flags false
for edge in define-env.ts.
metadata:
internal: trueDCE + 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
ifwithoutelse: works for inlinenode:*specifiers but NOT forrequire('./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
Use if/else (not two independent if blocks) when assigning a variable conditionally on process.env.X. TypeScript cannot prove exhaustiveness across if (flag) { x = a }; if (!flag) { x = b } and will error with "variable used before being assigned". The if/else pattern satisfies both TypeScript (definite assignment) and webpack DCE.
Compile-Time Switcher Pattern
Platform-specific code (node vs web) can use a single .ts switcher module that conditionally require()s either .node.ts or .web.ts into a typed variable, then re-exports the shared runtime API as named exports. Keep the branch as if/else so DefinePlugin can dead-code-eliminate the unused require(). Keep shared types canonical in .node.ts, with .web.ts importing them via import type and the switcher re-exporting types as needed. Examples: stream-ops.ts and debug-channel-server.ts.
NEXT_RUNTIME Is Not a Feature Flag
In user-project webpack server compilers, process.env.NEXT_RUNTIME is inlined to 'nodejs'. Guarding Node-only require('node:*') paths with NEXT_RUNTIME === 'nodejs' does not prune anything. For feature-gated codepaths, guard on the real feature define (e.g. process.env.__NEXT_USE_NODE_STREAMS).
Edge Runtime Constraints
Edge routes do NOT use pre-compiled runtime bundles. They are compiled by the user's webpack/Turbopack, so define-env.ts controls DCE. Feature flags that gate node:* imports must be forced to false for edge builds in define-env.ts (isEdgeServer ? false : flagValue), otherwise webpack will try to resolve node:stream etc. and fail.
app-page.ts Template Gotchas
app-page.tsis a build template compiled by the user's bundler. Anyrequire()in this file is traced by webpack/turbopack atnext buildtime. You cannot require internal modules with relative paths because they won't be resolvable from the user's project. Instead, export new helpers fromentry-base.tsand access them viaentryBase.*in the template.- Template helpers should stay out of
RenderResult. Ifapp-page.tsneeds a Node-stream-only utility, prefer a small dedicated helper module inserver/stream-utils/(with DCE-safeif/else+require()).
Verification
- Validate edge bundling regressions with
pnpm test-start-webpack test/e2e/app-dir/app/standalone.test.ts - For module-resolution/build-graph fixes, verify without
NEXT_SKIP_ISOLATE=1
Related Skills
$flags- flag wiring (config/schema/define-env/runtime env)$react-vendoring- entry-base boundaries and vendored React$runtime-debug- reproduction and verification workflow
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 DCE 安全的 require() 模式与边缘运行时约束的具体实现方案
- 涵盖 TypeScript 明确赋值、NEXT_RUNTIME 与功能标志区别等关键细节
- 包含验证命令与测试路径,具备可操作性
亮点
- 触发场景描述精准,覆盖 conditional require、Node-only imports、define-env 编辑等核心用例
- 边界清晰,能有效区分适用与不适用场景
待提升项
-
缺少 When to Use 章节与文档过长 原报告严重程度:轻微
文档未设置显式的 'When to Use' 章节标题,且内容长度超过 500 行
改进建议:建议添加 'When to Use' 章节以提升可读性,并考虑拆分超长内容为子章节
亮点
- 文档结构逻辑清晰,分节合理,代码示例充分
- frontmatter 完整,元数据标注 internal: true 符合规范
亮点
- 提供具体验证命令(pnpm test-start-webpack)与测试文件路径
- 明确指出常见误用场景(如 NEXT_SKIP_ISOLATE 的跳过问题)
- 工具来源与参数说明清晰,覆盖主要异常处理
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。