swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.72k stars 71 forks source link

register/esm load result mismatch #696

Closed jacogr closed 1 year ago

jacogr commented 1 year ago

Really happy to see the register/esm appearing. This is brilliant.

I'm using the latest Node LTS 18 and the currently-released 1.6.2.

Using this combo, I receive the following error when passing --loader @swc-node/register/esm on a project -

TypeError [ERR_INVALID_RETURN_PROPERTY_VALUE]: Expected a url string to be returned for the "url" from the "@swc-node/register/esm 'resolve'" function but got instance of String.
         at new NodeError (node:internal/errors:399:5)
         at ESMLoader.resolve (node:internal/modules/esm/loader:882:15)
         at async ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:7)
         at async ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:79:21) {
       code: 'ERR_INVALID_RETURN_PROPERTY_VALUE'

Based on the (current) Node loader documentation the return should be something like url: new URL(url).href (using the as-is code)

malins commented 1 year ago

I'm getting the same exception.

My project is using module/moduleResolution=NodeNext. Is that already supported by SWC-node?

Brooooooklyn commented 1 year ago

@jacogr What is the exact version of Node.js you have?

jacogr commented 1 year ago

The above was Node 18.14 - same issue on latest 18.15.

The return type is incorrect (as introduced in Node 16.12 with the latest loader API).

I do believe the merged https://github.com/swc-project/swc-node/pull/698 fixes this issue (looking at the changes made), so can be closed.