-
I want to run import tsNode, { createEsmHooks } from 'ts-node';
// register(process.cwd(), 'tsconfig.json');
createEsmHooks(
tsNode.register({
files: true,
transpileOnly: true,
esm: true,
}),
);
(async () => {
await import('./main.ts');
})(); but give me an error
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Node makes installing ESM hooks at runtime impossible, the only way is via the |
Beta Was this translation helpful? Give feedback.
-
This method is really troublesome. It is perfect to run the node code directly in ts-node as before, and the speed is also good after combining with swc. Some small ts projects can even run in the production environment without compiling. The experience is almost similar to the golang experience . |
Beta Was this translation helpful? Give feedback.
Node makes installing ESM hooks at runtime impossible, the only way is via the
--loader
flag. I'm on mobile but if you search around you may find discussions where people have written their own--loader
but use our API to implement it. Basically, they're doingnode --loader my-fancy-loader.js
and then in that file, they're using our API to create the hooks, possibly wrapping or customizing in some way.