Skip to content

Commit cadc145

Browse files
committed
fix(serve): alias culori to its ESM entry for Vite 8 dep optimizer
Aliasing to the package dir bypasses culori's exports map, so dir resolution picks its UMD bundle. Vite 8 marks that needsInterop and default-imports it, breaking culori's named-only ESM exports.
1 parent 0f29ccb commit cadc145

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/serve.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ const pkg = (name: string) => {
3434
return resolved.slice(0, idx + marker.length)
3535
}
3636

37+
/**
38+
* Resolve a package's ESM entry via its `exports` map. Aliasing to the
39+
* package directory bypasses `exports` (it only keys off the bare name),
40+
* so directory resolution can fall back to a UMD/CJS bundle — which Vite 8
41+
* flags `needsInterop` and then default-imports, breaking ESM-only deps
42+
* like culori (named exports, no default). Point the alias at the real
43+
* ESM entry instead.
44+
*/
45+
const pkgEsmEntry = (name: string) => {
46+
const dir = pkg(name)
47+
const pj = JSON.parse(readFileSync(resolve(dir, 'package.json'), 'utf-8'))
48+
const entry = pj.exports?.['.']?.import ?? pj.module ?? pj.main
49+
return resolve(dir, entry)
50+
}
51+
3752
export interface ServeOptions {
3853
config?: Partial<MaizzleConfig> | string
3954
/** Override the dev server port (takes precedence over config.server.port) */
@@ -82,7 +97,9 @@ export async function serve(options: ServeOptions = {}) {
8297
alias: [
8398
{ find: '@', replacement: devUIDir },
8499
{ find: 'vue', replacement: resolve(pkg('vue'), 'dist/vue.runtime.esm-bundler.js') },
85-
...['vue-router', 'reka-ui', '@vueuse/core', '@vueuse/shared', '@lucide/vue', 'class-variance-authority', 'clsx', 'tailwind-merge', 'culori']
100+
// culori is ESM-only — alias to its ESM entry, not the package dir (see pkgEsmEntry)
101+
{ find: 'culori', replacement: pkgEsmEntry('culori') },
102+
...['vue-router', 'reka-ui', '@vueuse/core', '@vueuse/shared', '@lucide/vue', 'class-variance-authority', 'clsx', 'tailwind-merge']
86103
.map(name => ({ find: name, replacement: pkg(name) })),
87104
],
88105
},

0 commit comments

Comments
 (0)