laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.19k stars 154 forks source link

vitest and isolted-vm incompatible? #481

Open ludusrusso opened 4 months ago

ludusrusso commented 4 months ago

I'm having some problems running isolated-vm inside a vitest test after upgrading to node 20.

With node 18.x it works well, after switching to node v20 I have a segmentation fault [1] 2778 segmentation fault pnpm run test

Quite sure this is releated with --no-node-snapshot but it seems it is incompatible with vitest. I've read the docs of vitest and it seems is not possible to de-opt from vitest js vm.

This is what happens when I run vitest with NODE_OPTIONS=--no-node-snapshot

Error: Initiated Worker with invalid NODE_OPTIONS env variable: --no-node-snapshot is not allowed in NODE_OPTIONS
 ❯ new Worker node:internal/worker:225:13
 ❯ ThreadWorker.initialize ../../node_modules/.pnpm/tinypool@0.8.3/node_modules/tinypool/dist/esm/index.js:139:19
 ❯ ThreadPool._addNewWorker ../../node_modules/.pnpm/tinypool@0.8.3/node_modules/tinypool/dist/esm/index.js:678:12
 ❯ ThreadPool._ensureMinimumWorkers ../../node_modules/.pnpm/tinypool@0.8.3/node_modules/tinypool/dist/esm/index.js:663:12
 ❯ new ThreadPool ../../node_modules/.pnpm/tinypool@0.8.3/node_modules/tinypool/dist/esm/index.js:648:10
 ❯ new Tinypool ../../node_modules/.pnpm/tinypool@0.8.3/node_modules/tinypool/dist/esm/index.js:950:31
 ❯ createThreadsPool ../../node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:8776:16
 ❯ threads ../../node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:9425:22
 ❯ ../../node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:9450:39

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_WORKER_INVALID_EXEC_ARGV' }
laverdet commented 4 months ago

This is a bug in vitest. They should not be naively passing NODE_OPTIONS into Worker like this. If you can somehow delete process.env.NODE_OPTIONS then it will probably work. Or you can run vitest via: node --no-node-snapshot node_modules/vitest/dist/cli-wrapper.js. But I think you might run into more problems.