es-module-shims icon indicating copy to clipboard operation
es-module-shims copied to clipboard

How is the browser downgraded if it does not support dynamic import?

Open lzxb opened this issue 7 months ago • 9 comments

What should I do if my browser supports module but does not support dynamic import?

lzxb avatar May 22 '25 03:05 lzxb

If your browser does not support dynamic import, you should use an older version of es-module-shims that polyfills dynamic import. Perhaps try version 1.10.1.

guybedford avatar May 23 '25 04:05 guybedford

Is there any solution that is compatible with the latest version?

lzxb avatar May 23 '25 06:05 lzxb

I am building a web application framework using importmap and ESM, and I am thinking about how to make it compatible with lower versions of browsers

lzxb avatar May 23 '25 06:05 lzxb

I saw that version 2.0 is based on browser support for dynamic import() compatibility

lzxb avatar May 23 '25 09:05 lzxb

Can es-module-shims provide a callback function when compatibility is not available?

I will provide a page similar to this Image

lzxb avatar May 23 '25 09:05 lzxb

Very few browsers do not support dynamic import, so the minimum versions here are actually very low.

See https://caniuse.com/es6-module-dynamic-import.

The main thing is Firefox before 67 and Safari before 11.1, IE, or edge below 79.

I'd be surprised if you find many users here at all.

guybedford avatar May 24 '25 16:05 guybedford

We have many users in China and often receive feedback. I hope there is a hook that can tell the browser that it is no longer supported and prompt users to upgrade their browser

lzxb avatar May 28 '25 01:05 lzxb

If es-module-shims didn't tell me, I don't know if it's working.

lzxb avatar May 28 '25 01:05 lzxb

You might try adding something like the following to the top of the page:

<script>
(function () {
  var dynamicImportSupported = false;
  try { eval("import(m)") } catch (e) { if (e instanceof ReferenceError) dynamicImportSupported = true }
  if (!dynamicImportSupported) {
    alert('This browser does not support modern JavaScript modules, make sure to use Chrome 79+, Firefox 67+, Safari 11.1+');
  }
})();
</script>

guybedford avatar May 31 '25 01:05 guybedford