ts-node
ts-node copied to clipboard
Node VM
Currently ts-node is not possible to use in combination with the node vm module.
You are not able to use any typescript code in a vm.
A simple way to reproduce it:
const code = `const test: boolean = true;`;
const vm = require('vm');
const s = new vm.Script(code); // Throws error
I can not find any issue related to this problem. However, I think there should be a way to make ts-node work with nodes vm.
It might work if you add a require in the vm code:
const code = `require('node-ts/register');require('vm.ts')`
const vm = require('vm')
const s = new vm.Script(code)
// vm.ts
const test: boolean = true;
However, there is no way to detect if the non vm process is running with ts-node.
You would need to ensure it is installed as a dependency but it shouldn't matter if the main process is pre-compiled or not.
It adds unnecessary overhead without a way to detect ts-node.
It adds unnecessary overhead without a way to detect ts-node.
I'm not sure what this means, why is this necessary?
I think there should be a way to make ts-node work with nodes vm.
You would probably have to write something built into ts-node
that re-exports vm
with wrappers around compiling down TypeScript. I'm happy to accept a PR for this work.