diff --git a/packages/dev-server-rollup/src/rollupAdapter.ts b/packages/dev-server-rollup/src/rollupAdapter.ts index fb4aeb41..a9009096 100644 --- a/packages/dev-server-rollup/src/rollupAdapter.ts +++ b/packages/dev-server-rollup/src/rollupAdapter.ts @@ -77,7 +77,7 @@ export function rollupAdapter( let fileWatcher: FSWatcher; let config: DevServerCoreConfig; let rootDir: string; - let idResolvers: ResolveIdHook[] = []; + let idResolvers: Array['resolveId']> = []; function savePluginMeta( id: string, @@ -123,14 +123,18 @@ export function rollupAdapter( Array.isArray(transformedOptions.plugins) ) { for (const subPlugin of transformedOptions.plugins) { - if (subPlugin && !Array.isArray(subPlugin) && (subPlugin as RollupPlugin).resolveId) { - idResolvers.push((subPlugin as RollupPlugin).resolveId as ResolveIdHook); + if (subPlugin && !Array.isArray(subPlugin)) { + const resolveId = (subPlugin as RollupPlugin).resolveId; + + if (resolveId) { + idResolvers.push(resolveId); + } } } } if (rollupPlugin.resolveId) { - idResolvers.push(rollupPlugin.resolveId as ResolveIdHook); + idResolvers.push(rollupPlugin.resolveId); } }, @@ -205,15 +209,15 @@ export function rollupAdapter( } for (const idResolver of idResolvers) { - if (typeof idResolver === 'function') { - result = await idResolver?.call(rollupPluginContext, resolvableImport, filePath, { - ...resolveOptions, - assertions: { - ...((resolveOptions?.assertions as Record) ?? {}), - }, - isEntry: false, - }); - } + const idResolverHandler = + typeof idResolver === 'function' ? idResolver : idResolver.handler; + result = await idResolverHandler.call(rollupPluginContext, resolvableImport, filePath, { + ...resolveOptions, + assertions: { + ...((resolveOptions?.assertions as Record) ?? {}), + }, + isEntry: false, + }); if (result) { break;