ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

Node VM

Open TheNoim opened this issue 5 years ago • 5 comments

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.

TheNoim avatar Mar 17 '19 11:03 TheNoim

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;

justinmchase avatar May 30 '19 17:05 justinmchase

However, there is no way to detect if the non vm process is running with ts-node.

TheNoim avatar May 31 '19 14:05 TheNoim

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.

justinmchase avatar May 31 '19 14:05 justinmchase

It adds unnecessary overhead without a way to detect ts-node.

TheNoim avatar May 31 '19 15:05 TheNoim

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.

blakeembrey avatar Nov 11 '19 02:11 blakeembrey