Instructions on using esm version to readme
jehna opened this issue · comments
The ESM build in version 2.1.6
of ga-lite
contains references of webpack
: https://unpkg.com/browse/ga-lite@2.1.6/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 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/ga-lite@2.1.6/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.
@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/ga-lite@2.1.6/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.