aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
738 stars 128 forks source link

Support dynamic import() from ES6 module #180

Open BeeDice opened 9 months ago

BeeDice commented 9 months ago

To reproduce:

<head>
    <script type="module">
        import('https://cdnjs.cloudflare.com/ajax/libs/jsmediatags/3.9.5/jsmediatags.min.js');
    </script>
</head>

Error:

Uncaught TypeError: Cannot use 'in' operator to search for 'Object' in undefined
    at $jscomp.polyfill (jsmediatags.min.js:2:113)
    at jsmediatags.min.js:2:257

Reason is that this is undefined in ES6 modules:

$jscomp.global = $jscomp.getGlobal(this);  // === undefined

I understand we use this here to support Node. Can getGlobal() return window if it is passed undefined?

Cattn commented 3 days ago

This.