swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.68k stars 67 forks source link

fix(esm-resolver): only return early if the specifier is an unsupported file #789

Closed fargito closed 1 week ago

fargito commented 2 weeks ago

Hello,

I encountered an issue with @swc-node/register@1.9.2 that did not happen with version 1.9.1

Description

Pull requests with the issue:

Both projects are esm-only, with Node v20.14.0, running swc with node --import @swc-node/register/esm-register my-entrypoint.ts. Also they don't have extensions in the internal imports (i.e. import { foo } from './foo' and not import { foo } from './foo.js').

Investigation

In #777 the pattern matching for supported extensions, was fixed. It used to match every single string.

However, now that this pattern is correct, the condition used to check it the specifier was supported was no longer valid for extension-less specifiers.

E.g.

import { foo } from './foo.js'; 

Is correctly flagged as a supported specifier and processed by swc.

But:

import  { foo } from './foo';

Isn't flagged as supported, and then directly passed to the default NodeJS loader, which is unable to undestand it.

Proposed fix

Only apply the early return if the specifier explicitely refers to an unsupported file.

WDYT?

CLAassistant commented 2 weeks ago

CLA assistant check
All committers have signed the CLA.