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

Does not work with "type": "module" in package.json

Open monoclex opened this issue 5 years ago • 5 comments

node -r @swc-node/register index.ts seems to work, but only if "type": "module" isn't in package.json. I would give more details, but I don't know what the problem is myself.

Attached is a reproducible example of this bug.

monoclex avatar Oct 07 '20 23:10 monoclex

Have you tried change module field in tsconfig.json to esnext?

Brooooooklyn avatar Oct 20 '20 07:10 Brooooooklyn

I have the same issue. And it also reproduces with module: esnext in tsconfig.json.

zaboco avatar Feb 08 '21 08:02 zaboco

Related ts-node issue, might have more info https://github.com/TypeStrong/ts-node/issues/1007

fregante avatar Mar 09 '21 03:03 fregante

might need a --loader swc-node/esm?

thelinuxlich avatar May 20 '21 22:05 thelinuxlich

ts-node added swc support, and supports node ESM using a loader.

However, I have yet to find some way to get Jest tests running with native node ESM, which neither @swc/jest nor ts-node seem to cover...

janus-reith avatar Jan 06 '22 15:01 janus-reith