// the find
Rich-Harris/shimport
Use JavaScript modules in all browsers, including dynamic imports
A 2KB runtime shim from Rich Harris (of Rollup/Svelte fame) that rewrites `import`/`export` statements on the fly so ES modules, including dynamic `import()`, work in browsers that don't natively support them. It's aimed at anyone shipping ESM output who needs a fallback path for older browsers instead of a full bundler-based transpile.
The core trick is legitimately clever: it feature-detects dynamic import support with a `new Function()` probe and only loads the shim when needed, so modern browsers pay zero cost. The transform is narrowly scoped to import/export syntax rather than trying to be a general transpiler, which keeps it small and fast. It composes cleanly with Rollup's `esm` output format and code-splitting, so you don't need a separate build path for the fallback case.
It explicitly does not support cyclical dependencies or live bindings, which are both part of the real ES module spec and will silently misbehave rather than error. It relies on `fetch` + evaluating transformed source at runtime, which breaks under any CSP that disallows unsafe-eval or restrictive CORS — exactly the kind of environment where you'd want a fallback loader to work. Practically, given that dynamic `import()` has had near-universal browser support for years now, the actual use case this solves has mostly evaporated, and the repo's last push in mid-2024 with no real activity since suggests it's not being maintained for edge cases that do still come up (e.g., older WebViews).