edge-runtime icon indicating copy to clipboard operation
edge-runtime copied to clipboard

Does Edge Runtime use alternative vm instead of node:vm?

Open RookieAND opened this issue 2 years ago • 3 comments

Questions & Answers

Recently I'm interested in how does Edge Runtime work. I investigate some code in edge-runtime/vm and I found this code below.

import type { CreateContextOptions } from 'vm'
import { createContext, runInContext } from 'vm' // is it same as 'node:vm'? or alternative something?

But what I confused is where does vm module came from. In document, Edge Runtime doesn't use Node Runtime. so I think it's not equal to node:vm.

Can you explain about vm that edge runtume use?

Context of your question Help us to understand the mental roadmap we need to follow to reach the same question.

I want to know what type of vm edge runtime use. does it use vm-browserify ? or alternative something instead of node:vm ?

RookieAND avatar Feb 15 '24 02:02 RookieAND

Hello, it's the same 🤠

CleanShot 2024-02-15 at 12 06 49@2x

Kikobeats avatar Feb 15 '24 11:02 Kikobeats

@Kikobeats Thanks for replying! But I have one more question sadly.. That means Edge Runtime is running on Node Runtime? So it cannot use Node API because Edge runtime evaluate code in it's own sandbox environment?

Then how can we use Edge runtime in Edge server? Does that server need nodej Oh... I think I have tons of misunderstanding about this. But can you explain more if you have some time?

RookieAND avatar Feb 15 '24 11:02 RookieAND

When you run vercel dev or next dev, it's spawning a Node.js process that uses this project.

This project is simulating the Edge Runtime constraints you are going to experience when you deploy a Vercel Function

We are using Node.js for development, but you are not using it when you deploy to real infrastructure.

Hope this clarifies a bit!

Kikobeats avatar Feb 15 '24 16:02 Kikobeats