diff --git a/packages/register/esm.mts b/packages/register/esm.mts index a48cd0896..7f8409f31 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 === 'true') { + 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)