Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an ESM-friendly UMD wrapper #30

Open
fuweichin opened this issue Jun 4, 2020 · 2 comments · May be fixed by guest271314/js-untar#1 or #37
Open

Use an ESM-friendly UMD wrapper #30

fuweichin opened this issue Jun 4, 2020 · 2 comments · May be fixed by guest271314/js-untar#1 or #37

Comments

@fuweichin
Copy link

Overview
The UMD wrapper js-untar currently in use may cause an error in certain circumstances.

Steps to Reproduce:

<script type="module">
import '/node_modules/jquery/dist/jquery.min.js';/* global jQuery */
import '/node_modules/pako/dist/pako_inflate.min.js';/* global pako */
import '/node_modules/js-untar/build/dist/untar.js';/* global untar */ 
//...
</script>

jquery and pako are okay with native ESM loader, while js-untar will throw an error

TypeError: Cannot set property 'untar' of undefined

Possible Solution:
Use a more versatile variant of UMD, e.g. returnExportsGlobal.js

@guest271314
Copy link

In the browser I get the error

TypeError: Cannot set properties of undefined (setting 'untar')
    at untar.js:1:118
    at untar.js:1:123

using https://unpkg.com/js-untar@2.0.0/build/dist/untar.js.

Currently I handle the error and continue

try {
  await import('https://unpkg.com/js-untar@2.0.0/build/dist/untar.js');
} catch(e) {
   console.log(e);
} finally {
  // do stuff
}

@guest271314
Copy link

The TypeError is thrown due to

var global = window || this;

this is not defined in Ecmascript Modules. Substituting globalThis avoids the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants