Closed doichev-kostia closed 10 months ago
You can create a file to register @swc-node
hooks:
import {register} from 'node:module';
import { pathToFileURL } from "node:url";
register('@swc-node/register/esm', pathToFileURL('./'));
And use it in the --import
flag:
node --import ./register.js ./src/main.ts
Not wanting to create an extra entrypoint file I've found the inline option to work fine as well.
{
"scripts": {
"dev": "node --import 'data:text/javascript,import {register} from \"node:module\";import {pathToFileURL} from \"node:url\";register(\"%40swc-node/register/esm\",pathToFileURL(\"./\"));' src/main.ts"
}
}
This does make it quite verbose I hope a solution will emerge that lets us do this with a shorter syntax.
I have created a pr to support this #748
before merged, try use https://npmjs.com/swc-register-esm temporary
Note: looks like they backported it, because node 18 also emits this warning.
According to the node.js release notes for node 20.6 the
experimental loaders
API was deprecated in favour of theregister
API. Because of that, we need to usenode --import register.js file.ts
instead ofnode --loader @swc-node/register/esm file.ts
.Currently, it's not possible or not mentioned in the docs how to solve this issue with
@swc-node/register
and the error the users may have isReproduction and workaround
I've added a repo with the reproduction and possible workaround influenced by tsx.