Closed selfagency closed 2 years ago
Just started a brand new project and I'm having the same issue right out of the box
Ah ok, I just figured it out. If you have "type": "module"
specified in package.json
, Node will run in ESM mode, which is not compatible with transpilation from TypeScript. To run a Node script compiled with swc
(as opposed to transpiled with @swc/register
, you need to set "type": "module"
in package.json
— or, and this is what I'll do, give the compiled files .mjs
extensions.
@selfagency How did you fix this at the end? Can you share your command?
Any updates on this now that ts/node supports esm? https://www.typescriptlang.org/docs/handbook/esm-node.html