From efc5ee9b54249a978d1e23aaa68e132309b51dfa Mon Sep 17 00:00:00 2001 From: philSixZero Date: Thu, 11 Sep 2025 17:46:28 +0200 Subject: [PATCH 1/2] fix(@swc-node/register): import of dynamically loaded files; fixes #883 --- packages/register/esm.mts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/register/esm.mts b/packages/register/esm.mts index a48cd0896..4c13311fa 100644 --- a/packages/register/esm.mts +++ b/packages/register/esm.mts @@ -195,6 +195,18 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => { const parsedUrl = parseUrl(specifier) + if (context.parentURL && parsedUrl?.protocol === 'file:') { + debug('skip resolve: dynamic import', specifier); + return addShortCircuitSignal({ + ...context, + url: specifier, + importAttributes: { + ...context.importAttributes, + dynamic: true + } + }); + } + // as entrypoint, just return specifier if (!context.parentURL || parsedUrl?.protocol === 'file:') { debug('skip resolve: absolute path or entrypoint', specifier) @@ -281,6 +293,12 @@ const tsconfigForSWCNode = { export const load: LoadHook = async (url, context, nextLoad) => { debug('load', url, JSON.stringify(context)) + if (context.importAttributes.dynamic) { + debug('skip load: dynamic file url', url); + delete context.importAttributes.dynamic; + return nextLoad(url, context); + } + if (url.startsWith('data:')) { debug('skip load: data url', url) From 06a684ae627723b3a57757ea6e730112ad01348a Mon Sep 17 00:00:00 2001 From: philSixZero Date: Tue, 23 Sep 2025 13:24:06 +0200 Subject: [PATCH 2/2] fix: type error --- packages/register/esm.mts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/register/esm.mts b/packages/register/esm.mts index 4c13311fa..7f8409f31 100644 --- a/packages/register/esm.mts +++ b/packages/register/esm.mts @@ -196,15 +196,15 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => { const parsedUrl = parseUrl(specifier) if (context.parentURL && parsedUrl?.protocol === 'file:') { - debug('skip resolve: dynamic import', specifier); + debug('skip resolve: dynamic import', specifier) return addShortCircuitSignal({ ...context, url: specifier, importAttributes: { ...context.importAttributes, - dynamic: true - } - }); + dynamic: 'true', + }, + }) } // as entrypoint, just return specifier @@ -293,10 +293,10 @@ const tsconfigForSWCNode = { export const load: LoadHook = async (url, context, nextLoad) => { debug('load', url, JSON.stringify(context)) - if (context.importAttributes.dynamic) { - debug('skip load: dynamic file url', url); - delete context.importAttributes.dynamic; - return nextLoad(url, context); + if (context.importAttributes.dynamic === 'true') { + debug('skip load: dynamic file url', url) + delete context.importAttributes.dynamic + return nextLoad(url, context) } if (url.startsWith('data:')) {