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

Instructions on using esm version to readme #463

Open
jehna opened this issue Mar 8, 2022 · 4 comments
Open

Instructions on using esm version to readme #463

jehna opened this issue Mar 8, 2022 · 4 comments

Comments

@jehna
Copy link
Owner

jehna commented Mar 8, 2022

No description provided.

@hoangvvo
Copy link

hoangvvo commented Mar 13, 2022

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.

@jehna
Copy link
Owner Author

jehna commented Mar 13, 2022

The ESM build was just recently added in #458

Would @kidonng have an idea why this is happening?

@jehna
Copy link
Owner Author

jehna commented Mar 13, 2022

@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
Copy link

hoangvvo commented Mar 13, 2022

@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.

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

No branches or pull requests

2 participants