swc-node
swc-node copied to clipboard
[WIP]: experimental esm loader
- Close: https://github.com/Brooooooklyn/swc-node/issues/634
- Close: https://github.com/Brooooooklyn/swc-node/issues/383
- Close: https://github.com/Brooooooklyn/swc-node/issues/120
We're eagerly waiting for top-level await support.
Can we do anything to help test this?
Stuck on ESM support as well, looking forward to this PR merge!
Is something blocking this change from being merged?
also waiting for this!
Any way how to progress this PR?
esm/esm.js
is not included in v1.6.0, so @swc-node/register/esm
does not work
> cat node_modules/@swc-node/register/package.json | rg version
"version": "1.6.0",
> ls node_modules/@swc-node/register
LICENSE README.md index.js lib node_modules package.json read-default-tsconfig.d.ts register.d.ts
Also, seems node -r @swc-node/register/esm
is using require()
, it failed to recognize /esm
Error: Package subpath './esm' is not defined by "exports" in node_modules/@swc-node/register/package.json
Can someone shed some light on how to use this now that it's fixed?
test.ts
import got from 'got';
const { data } = await got
.post('https://httpbin.org/anything', {
json: {
hello: 'world',
},
})
.json<{data: unknown}>();
console.log(data);
node -r @swc/register test.ts
node:internal/errors:490
ErrorCaptureStackTrace(err);
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /foo/test.ts
@jensbodal you should use loader
for esm. read the docs
node --loader @swc-node/register/esm test.ts
Thank you that worked
And my bad I see it in the docs here: https://github.com/swc-project/swc-node#usage
Can we use both -r
and --loader
at the same time? Or does that not make sense?
@weyert yes you can use. but i can't tell you something makes sense or not without seeing the actual code.