Filed a Node.js issue as a last resort 😭. If CommonJS supports `import()`, why doesn’t `vm` support `import()`?
https://github.com/nodejs/node/issues/51154
Or, I’d love a stable `vm.Module`! Or Node.js ShadowRealms! I shouldn’t have to use a bundler for this stuff.
9 replies
I see this experimental limbo for Node.js’ ESM `vm.Module` causing large scale problems elsewhere too, right?
Jest seems to be trying to stick to Node.js APIs (which is a good goal!) and people are migrating to Vitest for “stable” ESM support—but Vitest is using `esbuild` to sidestep the experimental status.
Looks like Vite writes a temporary file to the file system to work around this issue 👀 https://github.com/vitejs/vite/blob/77d5165e2f252bfecbb0eebccc6f04dc8be0c5ba/packages/vite/src/node/config.ts#L1172-L1184
@zachleat We tried to remove the temporary file by using `data:` and had to revert it, but we may try again at one point. That temporary file is a terrible hack.
https://github.com/vitejs/vite/issues/13267#issuecomment-1624779173@patak yeah—I don’t blame y’all for going down that road. It would be nice to have a stable vm.Module. It would solve a lot of ESM migration pain!
@patak in some code paths I use the weird Module#_compile trick to allow dynamic import() in CJS (I think I picked it up from Svelte at one point) https://github.com/zachleat/node-retrieve-globals/blob/4fbf1e474e7fedfa79f847e4ebc5d0d2075f9b27/retrieveGlobals.js#L270-L272 (oh and https://github.com/zachleat/esm-import-transformer/ to transform `import` to dynamic `import` 😓)
so many tricks!
@zachleat I wouldn't count on VM / realms stuff, they've been unstable in a number of ways for 10+ years.
Do workers fulfill your needs?
Alert Alert: We have movement, we have movement!
A fully fledged PR to fix the issue (with a warning instead of an error): https://github.com/nodejs/node/pull/51244
Exciting!
@zachleat Just want to add, as someone helping out where I can on the node project, and also deeply interested in the health of the web and OSS, that the folks on Node.js, in general care deeply about their project, their ecosystem, and their community.
At the collab summit this summer, I saw them celebrating 10 years, AND planning for the next 10.
Node.js may not have the alacrity or flash of bun...etc, because they have the burden of momentum.
Glad you reached out!
@brian well said! Node.js has staying power—I’d kinda be surprised if Bun is still around in 5 years