AgentSkillsCN

create-next-app-existing-dir

当您在现有目录中运行 create-next-app(例如 backend/)时:若工具拒绝覆盖现有 package.json,可将其移除或重命名;优先使用目标路径的绝对路径;对于仅包含 API 的项目,应在重新运行类型检查之前,剥离 UI(布局、页面、全局变量、public 目录),并清空 .next 文件夹。当您在现有文件夹中搭建 Next.js 项目时,可使用此技能。

SKILL.md
--- frontmatter
name: create-next-app-existing-dir
description: When running create-next-app in an existing directory (e.g. backend/): remove or rename existing package.json if the tool refuses to overwrite; prefer absolute path for target; for API-only setups, strip UI (layout, page, globals, public) and clear .next before re-running type-check. Use when scaffolding Next.js in an existing folder.

Create-Next-App in Existing Directory

When running create-next-app inside an existing directory (e.g. backend/):

Checklist

  1. Existing package.json: If the tool refuses to overwrite, remove or rename the existing package.json in that directory before re-running.
  2. Target path: Prefer an absolute path for the target directory to avoid cd/sandbox issues.
  3. API-only setup: For API-only backends, after scaffolding: strip UI (layout, page, globals, public) as needed and clear .next before re-running type-check.

Optional

  • Link to monorepo-backend-layout so the agent treats the backend directory as the app root.

Why This Matters

Tasks have lost ~20–25 seconds to create-next-app retries (existing package.json, then path issues). A short checklist prevents repeated failures.