migrate-to-vinext

작성자: cloudflare

Next.js에서 vinext(Next.js의 Vite 기반 재구현)로의 자동 마이그레이션. 단일 vinext init 명령어 또는 수동 대체 단계를 통해 호환성 스캔, 패키지 교체, Vite 설정 생성, ESM 변환을 처리합니다. App Router와 Pages Router를 모두 지원하며, 기존 app/, pages/, next.config.js는 변경 없이 그대로 작동합니다 — 애플리케이션 코드 수정이 필요하지 않습니다. vinext deploy를 통한 네이티브 Cloudflare Workers 배포를 포함하며, 바인딩(D1, R2, KV, AI)에 직접 접근할 수 있습니다...

npx skills add https://github.com/cloudflare/vinext --skill migrate-to-vinext

Migrate Next.js to vinext

vinext reimplements the Next.js API surface on Vite. Existing app/, pages/, and next.config.js work as-is — migration is a package swap, config generation, and ESM conversion. No changes to application code required.

FIRST: Verify Next.js Project

Confirm next is in dependencies or devDependencies in package.json. If not found, STOP — this skill does not apply.

Detect the package manager from the lockfile:

LockfileManagerInstallUninstall
pnpm-lock.yamlpnpmpnpm addpnpm remove
yarn.lockyarnyarn addyarn remove
bun.lockb / bun.lockbunbun addbun remove
package-lock.json or nonenpmnpm installnpm uninstall

Detect the router: if an app/ directory exists at root or under src/, it's App Router. If only pages/ exists, it's Pages Router. Both can coexist.

Quick Reference

CommandPurpose
vinext checkScan project for compatibility issues, produce scored report
vinext initAutomated migration — installs deps, generates config, converts to ESM
vinext devDevelopment server with HMR
vinext buildProduction build (multi-environment for App Router)
vinext startLocal production server
vinext deployBuild and deploy to Cloudflare Workers

Phase 1: Check Compatibility

Run vinext check (install vinext first if needed via npx vinext check). Review the scored report. If critical incompatibilities exist, inform the user before proceeding.

See references/compatibility.md for supported/unsupported features and ecosystem library status.

Phase 2: Automated Migration (Recommended)

Run vinext init. This command:

  1. Runs vinext check for a compatibility report
  2. Installs vite as a devDependency (and @vitejs/plugin-rsc for App Router)
  3. Adds "type": "module" to package.json
  4. Renames CJS config files (e.g., postcss.config.js.cjs) to avoid ESM conflicts
  5. Adds dev:vinext and build:vinext scripts to package.json
  6. Generates a minimal vite.config.ts

This is non-destructive — the existing Next.js setup continues to work alongside vinext. Use the dev:vinext script to test before fully switching over.

If vinext init succeeds, skip to Phase 4 (Verify). If it fails or the user prefers manual control, continue to Phase 3.

Phase 3: Manual Migration

Use this as a fallback when vinext init doesn't work or the user wants full control.

3a. Replace packages

# Example with npm:
npm uninstall next
npm install vinext
npm install -D vite
# App Router only:
npm install -D @vitejs/plugin-rsc

3b. Update scripts

Replace all next commands in package.json scripts:

BeforeAfterNotes
next devvinext devDev server with HMR
next buildvinext buildProduction build
next startvinext startLocal production server
next lintvinext lintDelegates to eslint/oxlint

Preserve flags: next dev --port 3001vinext dev --port 3001.

3c. Convert to ESM

Add "type": "module" to package.json. Rename any CJS config files:

  • postcss.config.jspostcss.config.cjs
  • tailwind.config.jstailwind.config.cjs
  • Any other .js config that uses module.exports

3d. Generate vite.config.ts

See references/config-examples.md for config variants per router and deployment target.

If the project already has custom Vite config, prefer Vite 8-native keys when editing it: oxc, optimizeDeps.rolldownOptions, and build.rolldownOptions. Older esbuild and build.rollupOptions settings still work for now but are migration targets.

Pages Router (minimal):

import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });

App Router (minimal):

import vinext from "vinext";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [vinext()] });

vinext auto-registers @vitejs/plugin-rsc for App Router when the rsc option is not explicitly false. No manual RSC plugin config needed for local development.

Phase 4: Deployment (Optional)

Option A: Cloudflare Workers (recommended for Cloudflare)

If the user wants to deploy to Cloudflare Workers, use vinext deploy. It auto-generates wrangler.jsonc, worker entry, and Vite config if missing, installs @cloudflare/vite-plugin and wrangler, then builds and deploys.

For manual setup or custom worker entries, see references/config-examples.md.

Cloudflare Bindings (D1, R2, KV, AI, etc.)

To access Cloudflare bindings (D1, R2, KV, AI, Queues, Durable Objects, etc.), use import { env } from "cloudflare:workers" in any server component, route handler, or server action:

import { env } from "cloudflare:workers";

export default async function Page() {
  const result = await env.DB.prepare("SELECT * FROM posts").all();
  return <div>{JSON.stringify(result)}</div>;
}

This works because @cloudflare/vite-plugin runs server environments in workerd, where cloudflare:workers is a native module. No custom worker entry, no getPlatformProxy(), no special configuration needed. Just import and use.

Bindings must be defined in wrangler.jsonc. For TypeScript types, run wrangler types.

IMPORTANT: Do not use getPlatformProxy(), getRequestContext(), or custom worker entries with fetch(request, env) to access bindings. These are older patterns. cloudflare:workers is the recommended approach and works out of the box with vinext.

Option B: Other platforms (via Nitro)

For deploying to Vercel, Netlify, AWS, Deno Deploy, or any other Nitro-supported platform, add the Nitro Vite plugin:

npm install nitro
// vite.config.ts
import { defineConfig } from "vite";
import vinext from "vinext";
import { nitro } from "nitro/vite";

export default defineConfig({
  plugins: [vinext(), nitro()],
});

Build and deploy:

NITRO_PRESET=vercel npx vite build    # Vercel
NITRO_PRESET=netlify npx vite build   # Netlify
NITRO_PRESET=deno_deploy npx vite build  # Deno Deploy
NITRO_PRESET=node npx vite build      # Node.js server

Nitro auto-detects the platform in most CI/CD environments, so the preset is often unnecessary.

Note: For Cloudflare Workers, Nitro works but the native integration (vinext deploy / @cloudflare/vite-plugin) is recommended for the best developer experience with cloudflare:workers bindings, KV caching, and one-command deploys.

Phase 5: Verify

  1. Run vinext dev to start the development server
  2. Confirm the server starts without errors
  3. Navigate key routes and check functionality
  4. Report the result to the user — if errors occur, share full output

See references/troubleshooting.md for common migration errors.

Known Limitations

FeatureStatus
next/image optimizationRemote images via @unpic; no build-time optimization
next/font/googleCDN-loaded, not self-hosted
Domain-based i18nNot supported; path-prefix i18n works
next/jestNot supported; use Vitest
Turbopack/webpack configIgnored; use Vite plugins instead
runtime / preferredRegionRoute segment configs ignored
PPR (Partial Prerendering)Use "use cache" directive instead (Next.js 16 approach)

Anti-patterns

  • Do not modify app/, pages/, or application code. vinext shims all next/* imports — no import rewrites needed.
  • Do not rewrite next/* imports to vinext/* in application code. Imports like next/image, next/link, next/server resolve automatically.
  • Do not copy webpack/Turbopack config into Vite config. Use Vite-native plugins instead.
  • Do not skip the compatibility check. Run vinext check before migration to surface issues early.
  • Do not remove next.config.js unless replacing it with next.config.ts or .mjs. vinext reads it for redirects, rewrites, headers, basePath, i18n, images, and env config.
  • Do not use getPlatformProxy() or custom worker entries for bindings. Use import { env } from "cloudflare:workers" instead. This is the modern pattern and works out of the box with vinext and @cloudflare/vite-plugin.
  • For Cloudflare Workers, prefer the native integration over Nitro. vinext deploy / @cloudflare/vite-plugin provides the best experience with cloudflare:workers bindings, KV caching, and image optimization. Nitro works for Cloudflare but the native setup is recommended.

cloudflare의 다른 스킬

write-endpoints
cloudflare
chanfana를 사용한 OpenAPI 엔드포인트 구축을 위한 종합 가이드 - 스키마 정의, 요청 검증, CRUD 작업, D1 데이터베이스 통합 등
official
agents-sdk
cloudflare
Cloudflare Workers에서 Agents SDK를 사용하여 AI 에이전트를 구축하세요. 상태 저장 에이전트, 지속 가능한 워크플로우, 실시간 WebSocket 앱, 예약된 작업 등을 생성할 때 로드하세요.
official
building-ai-agent-on-cloudflare
cloudflare
Cloudflare의 Agents SDK를 사용하여 지속적 상태, 실시간 통신, 도구 통합을 갖춘 AI 기반 에이전트를 생성합니다.
official
building-mcp-server-on-cloudflare
cloudflare
Cloudflare Workers에서 도구, 인증, 배포를 포함한 프로덕션 준비 완료 Model Context Protocol 서버를 생성합니다.
official
changelog
cloudflare
Cloudflare 문서 사이트의 제품 변경 로그 항목을 생성, 업데이트 및 검토합니다. 변경 로그 MDX 파일을 생성하거나 기존 파일을 편집할 때 로드합니다.
official
cloudflare
cloudflare
Cloudflare 플랫폼 전반을 다루는 스킬로, Workers, Pages, 스토리지(KV, D1, R2), AI(Workers AI, Vectorize, Agents SDK), 네트워킹(Tunnel, Spectrum) 등을 포함합니다.
official
code-review
cloudflare
작업자 및 Cloudflare Developer Platform 코드의 타입 정확성, API 사용법, 구성 유효성을 검토합니다. TypeScript/JavaScript를 검토할 때 로드합니다…
official
docs-review
cloudflare
문서 PR을 검토하고 GitHub PR 제안을 제공합니다. 문서 내용에 대한 리뷰, 변경 제안 또는 피드백을 요청받을 때 로드됩니다. MDX 등을 다룹니다.
official