ga-lite icon indicating copy to clipboard operation
ga-lite copied to clipboard

Instructions on using esm version to readme

Open jehna opened this issue 3 years ago • 4 comments

jehna avatar Mar 08 '22 21:03 jehna

The ESM build in version 2.1.6 of ga-lite contains references of webpack: https://unpkg.com/browse/[email protected]/dist/ga-lite.esm.js. Is this expected? Attempting to use it results in the following error:

TypeError: Object.defineProperty called on non-object

at places with calls of Object.defineProperty(exports, .... I find it strange for webpack and module.exports to be referenced in that file.

hoangvvo avatar Mar 13 '22 08:03 hoangvvo

The ESM build was just recently added in #458

Would @kidonng have an idea why this is happening?

jehna avatar Mar 13 '22 10:03 jehna

@hoangvvo how are you using ga-lite? I tried a quick example with CodeSandbox and I could not reproduce your issue:

    <script type="module">
      import galite from "https://unpkg.com/[email protected]/dist/ga-lite.esm.js";

      galite("create", "UA-XXXXXXXX-X", "auto");
      console.log(galite);
    </script>

https://codesandbox.io/s/hidden-dew-lyhbus?file=/index.html

The error Object.defineProperty called on non-object sounds like you're trying to use ES module version witout ESM runtime (e.g. <script type="module">).

contains references of webpack

I think the source code does not contain references to webpack in itself, but it uses some module-local variables that it names with __webpack_ prefix, probably to avoid name clashes with the bundled source code. With a quick glance the script output looks good to me.

jehna avatar Mar 13 '22 10:03 jehna

@hoangvvo how are you using ga-lite? I tried a quick example with CodeSandbox and I could not reproduce your issue:

    <script type="module">
      import galite from "https://unpkg.com/[email protected]/dist/ga-lite.esm.js";

      galite("create", "UA-XXXXXXXX-X", "auto");
      console.log(galite);
    </script>

https://codesandbox.io/s/hidden-dew-lyhbus?file=/index.html

The error Object.defineProperty called on non-object sounds like you're trying to use ES module version witout ESM runtime (e.g. <script type="module">).

contains references of webpack

I think the source code does not contain references to webpack in itself, but it uses some module-local variables that it names with __webpack_ prefix, probably to avoid name clashes with the bundled source code. With a quick glance the script output looks good to me.

Thanks for the response! I am using it with Next.js with ESM enabled (which uses webpack) so it prefers the ESM version. I created a reproduction here: https://codesandbox.io/s/ga-lite-object-define-property-undefined-kn4lnv

Version 2.1.5 works fine for me.

hoangvvo avatar Mar 13 '22 11:03 hoangvvo