Next.js에서 Edge Runtime을 사용하는 이유와 제약

2025-12-07
Edge runtime의 사용은 낮은 지연(low latency)를 제공하기 위함이며, 제약은 환경의 통일성과 portable을 제공하기 위해서입니다.

https://nextjs.org/docs/app/api-reference/edge

Edge runtime

https://nextjs.org/docs/app/getting-started/proxy

Proxy
사용시 제한된 API를 제공하는 런타임입니다.
Edge runtime을 사용함으로써 다음과 같은 이점을 가질 수 있습니다.Vercel/Cloudflare로 배포하게된다면 Proxy는 전세계 edge locations에

https://developers.cloudflare.com/workers/reference/how-workers-works/#isolates

V8 Isolate
형태로 배포됩니다.
만약 self-hosting 환경이라면 어떻게 Proxy가 동작할까요?
Proxy는 Node.js의 vm 모듈을 사용하여 격리된 JavaScript 실행 환경을 만듭니다.

packages/next/src/server/web/sandbox/context.ts

import { runInContext } from 'vm' runInContext(content, moduleContext.runtime.context, { filename: filepath, }) moduleContext.paths.set(filepath, content)

따라서 단일 Node.js 프로세스 환경에서 Node.js 힙을 공유하게 되며 Edge Runtime의 이점을 가지지 못합니다.
하지만 Next.js는 동일한 환경을 제공하기 위해 제한된 Node.js API 제공 등의 작업을 수행합니다.
process.env를 사용할 수 있게 합니다.
const runtime = new EdgeRuntime({ codeGeneration: process.env.NODE_ENV !== 'production' ? { strings: true, wasm: true } : undefined, extend: (context) => { context.process = createProcessPolyfill(edgeFunctionEntry.env) function createProcessPolyfill(env: Record<string, string>) { // Edge Runtime에서 context.process = createProcessPolyfill(env) // 사용자 코드에서 process.env.NODE_ENV // ✅ 허용됨 process.cwd() // ❌ throwUnsupportedAPIError!

https://nextjs.org/docs/app/api-reference/edge#reference

제한된 API set
를 사용할 수 있게 합니다.
function addStub(context: EdgeRuntime['context'], name: string) { Object.defineProperty(context, name, { get() { return function () { throwUnsupportedAPIError(name) } }, enumerable: false, }) } for (const name of EDGE_UNSUPPORTED_NODE_APIS) { addStub(context, name) }
Web Standard API를 Next.js 요구사항에 맞게 커스터마이징합니다.
const __fetch = context.fetch context.fetch = async (input, init = {}) => { const callingError = new Error('[internal]') const assetResponse = await fetchInlineAsset({ input, assets: options.edgeFunctionEntry.assets, distDir: options.distDir, context, }) if (assetResponse) { return assetResponse } init.headers = new Headers(init.headers ?? {}) ...

ISR을 사용할 수 없는 이유도 동일합니다. ISR은 파일 시스템 캐싱을 사용해야 하지만 Edge Runtime에서는 fs 모듈 사용이 불가합니다.

참조 링크 :

https://plaintexting.com/knowledge_base-reviews/v8-isolate/

[Operating System] V8 Isolate
buy me a coffeebuy-me-a-coffee