Closed danieltroger closed 7 months ago
I looked into this a bit. I have no idea how this whole node module resolving works, but the error thrown originates from a worker with the url "node:internal/modules/esm/worker", but I don't know how to get a debugger into the worker
Ok I looked into this a bit more and it seems that what happens is:
readFileSync
is imported from fs
here https://github.com/nodejs/node/blob/main/lib/internal/modules/esm/translators.js#L35 but for some reason this is before yarn pnp has patched the fs moduleSee in this screenshot where pnp isn't in the stack trace when calling the readFileSync
function available in the scope and it fails, while require("fs").readFileSync
succeeds
For comparison, here's the correctly patched fs module's stack trace
In conclusion this seems to be an issue with yarn.
Edit: can confirm it's a yarn bug, swc-node works fine with npm
swc-node now works with node 21.2.0 without a problem, after updating to yarn 4.0.2 (thanks to https://github.com/yarnpkg/berry/pull/5961)
It seems like swc-node broke after node 20.5.1?
To reproduce, execute this:
You should see the following output:
Edit: same thing happens with node v21.1.0