From 52c76362ae011648f2a001ad8244dfcacebcf928 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 17 May 2026 11:15:50 +0200 Subject: [PATCH] fix(01-08): resolve ebml via CJS main entry to bypass Vite/Rollup tree-shake bug Vite's @rollup/plugin-commonjs failed to bridge ts-ebml's `require("ebml")` against ebml's mixed-main/module/browser package. Rollup tree-shook ebml.esm.js entirely, leaving `var Pc={}` as a dangling placeholder. ts-ebml/tools.js's destructure `{tools:f}=Pc` threw TypeError at SW top-level module init, blocking handler registration -> chrome://serviceworker-internals Status=STARTING forever. `resolve.alias: { ebml: 'ebml/lib/ebml.js' }` forces resolution to the CJS main entry whose assignment-style exports survive plugin-commonjs's namespace allocation. Empirically verified: bundle init progresses ~340 KB further; readVint error gone. Probes C1 (resolve.mainFields), C2 (treeshake.moduleSideEffects), C3 (C1+C2 combined), C4 (commonjsOptions.strictRequires) were all falsified before C-config landed. Resolves: .planning/debug/01-08-sw-incompatibility.md Co-Authored-By: Claude Opus 4.7 (1M context) --- vite.config.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index a41d252..52ed7ec 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,6 +11,11 @@ export default defineConfig({ }, }), ], + resolve: { + alias: { + ebml: 'ebml/lib/ebml.js', + }, + }, build: { rollupOptions: { input: {