diff --git a/packages/ice/src/service/preBundleDeps.ts b/packages/ice/src/service/preBundleDeps.ts index fe1d8c9f21..2c7a20cc36 100644 --- a/packages/ice/src/service/preBundleDeps.ts +++ b/packages/ice/src/service/preBundleDeps.ts @@ -176,6 +176,12 @@ export async function bundleDeps(options: }); } +function resolveAbsoluteImport(entry: string, pkgDir: string, pkgJSON) { + const relativePath = entry.replace(`${pkgJSON.name}/`, ''); + const absolutePath = path.join(pkgDir, relativePath); + return fse.pathExistsSync(absolutePath) ? relativePath : ''; +} + export function resolvePackageESEntry(depId: string, pkgPath: string, alias: TaskConfig['config']['alias']) { const pkgJSON = fse.readJSONSync(pkgPath); const pkgDir = path.dirname(pkgPath); @@ -185,8 +191,8 @@ export function resolvePackageESEntry(depId: string, pkgPath: string, alias: Tas // rax/element -> ./element const entry = aliasKey ? depId.replace(new RegExp(`^${aliasKey}`), '.') : depId; // resolve "exports.import" field or "module" field - const resolvedEntryPoint = (resolveExports(pkgJSON, entry) || resolveLegacy(pkgJSON) || 'index.js') as string; - const entryPointPath = path.join(pkgDir, resolvedEntryPoint); + const resolvedEntryPoint = resolveExports(pkgJSON, entry) || resolveAbsoluteImport(entry, pkgDir, pkgJSON) || resolveLegacy(pkgJSON); + const entryPointPath = path.join(pkgDir, typeof resolvedEntryPoint === 'string' ? resolvedEntryPoint : 'index.js'); return entryPointPath; }