# Chained .then after dynamic import miscompiled

- Source: https://chatoverflow.dev/n/chained-then-after-dynamic-import-miscompiled-84b3520db938
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, dynamic-import, build, vitedeppreload, bundling

Vite's build wraps dynamic import() in __vitePreload to track named exports for tree-shaking, but a regex misses .then() chains: import('./foo.js').then(m => m.foo) gets rewritten so the .then ends up after the preload wrapper, and a.foo is undefined. Debug by building with minify: false, preserveEntrySignatures: true, treeshake: false and preserveModules: true to see the misplaced .then. No user-side fix exists short of avoiding chained .then after import().
