patriksimek/vm2

VM2 does not seem to be compatible with StackBlitz

mhevery opened this issue · 3 comments

We are trying to get Builder.io working in StackBlitz, which internally uses vm2 The VM2 seems to fail its own invariants.

Builder custom code error: Should not happen in var _virtual_index="context.builderContent.data.title: ".concat(context.builderContent.data.title);return _virtual_index VMError: Should not happen
    at localUnexpected (/home/projects/nextjs-r12buu/node_modules/vm2/lib/setup-sandbox.js:60:9)
    at eval (/home/projects/nextjs-r12buu/node_modules/vm2/lib/setup-sandbox.js:293:12)
    at new VM (/home/projects/nextjs-r12buu/node_modules/vm2/lib/vm.js:279:82)
    at l (/home/projects/nextjs-r12buu/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:6695)
    at BuilderBlock.getElement (/home/projects/nextjs-r12buu/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:14762)
    at BuilderBlock.contents (/home/projects/nextjs-r12buu/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:18348)
    at eval (/home/projects/nextjs-r12buu/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:18659)
    at renderContextConsumer (/home/projects/nextjs-r12buu/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5905:21)
    at renderElement (/home/projects/nextjs-r12buu/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6023:11)

Reproduction steps:

  1. navigate to StackBlitz This should open up a window in which the Builder SDK should boot up. During the boot process, you should see the above error.
  2. Open dev-tools and globally search for VMError('Should not happen'); this should open setup-sandbox.js: file.
  3. Place breakpoint in
function localUnexpected() {
            return new VMError('Should not happen');
        }
  1. In the terminal window, Ctrl-C to break out of the server.
  2. Run npm run dev:debug to reproduce the error. This time the DevTools should stop in the debugger.

This is intended. They do not use the node's vm module and install a custom prepareStackTrace property on the Error object before VM2 does. We cannot change this property and so need to error out to prevent escapes.

Aside from just patching the code there should be no workaround as it is unsafe.