generator icon indicating copy to clipboard operation
generator copied to clipboard

`ts-node` is registered if `generator` is imported in a .js file

Open bakasmarius opened this issue 10 months ago • 6 comments

Describe the bug

ts-node is registered if @asyncapi/generator is simply imported in a file, even though the constructor or any other of generator's methods is not called at all. This means that after building a TypeScript project, when it is transpiled to JavaScript, ts-node is still registered, even though TypeScript is not needed anymore. This also means that ts-node is registered in a JavaScript project that does not use TypeScript at all. We noticed it because after adding nestjs-asyncapi (which uses @asyncapi/generator) to one of our bigger projects, the startup time of npm start increased by ~30 seconds.

How to Reproduce

Create a new file test.js which only imports @asyncapi/generator and does nothing else with it:

const { REGISTER_INSTANCE } = require('ts-node');
console.log(process[REGISTER_INSTANCE] == null); // prints "true"
const generator = require('@asyncapi/generator');
console.log(process[REGISTER_INSTANCE] == null); // prints "false"

run node test.js and look at the output

Expected behavior

ts-node is registered only when it's actually needed.

bakasmarius avatar Aug 21 '23 11:08 bakasmarius