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

[Bug]: esm version has no cookieConsent variable #656

Closed
ourmaninindia opened this issue Feb 29, 2024 · 7 comments
Closed

[Bug]: esm version has no cookieConsent variable #656

ourmaninindia opened this issue Feb 29, 2024 · 7 comments

Comments

@ourmaninindia
Copy link

Expected Behavior

after importing the esm version I get an error message that cookieConsent is not defined which is true. As a result I was forced to use the umd version.

I much prefer using the esm as I use ES6 vanilla javascript

Current Behavior

cookieConsent missing when using https://cdn.jsdelivr.net/gh/orestbida/cookieconsent@3.0.0/dist/cookieconsent.esm.js

Steps to reproduce

just open the file

Proposed fix or additional info.

export the cookieConsent variable as u=in the umd version

Version

3.0.0

On which browser do you see the issue?

Firefox

@ourmaninindia ourmaninindia added the bug Something isn't working label Feb 29, 2024
@github-actions github-actions bot added the triage yet to be reviewed label Feb 29, 2024
@orestbida
Copy link
Owner

I'm not sure I understand the issue.

The UMD version is attached to the window object and is globally accessible. The ESM version is imported in the current context only, which is the expected behavior of ESM, afaik.

@orestbida orestbida removed the triage yet to be reviewed label Feb 29, 2024
@dreinon
Copy link

dreinon commented Mar 13, 2024

Same issue here after importing

import CookieConsent from 'vanilla-cookieconsent';

I get this error:
image

@orestbida
Copy link
Owner

orestbida commented Mar 13, 2024

@dreinon there is no default export so that won't work.

You should use the import * syntax, as shown in the docs:

import * as CookieConsent from 'vanilla-cookieconsent';

@dreinon
Copy link

dreinon commented Mar 13, 2024

Right, it might be a good idea to also export it as default, since linters recommend you import as default instead of with "*"

@dreinon
Copy link

dreinon commented Mar 13, 2024

image

@orestbida
Copy link
Owner

It mostly boils down to personal preference.
I like the explicitness of named exports. They are more flexible and clearer to me.

This clearly conveys that you are willingfully loading everything:

import * as CookieConsent from 'vanilla-cookieconsent';

I would have used a default export if there was only one function exported.

@orestbida orestbida removed the bug Something isn't working label Mar 13, 2024
@ourmaninindia
Copy link
Author

ourmaninindia commented Mar 14, 2024 via email

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

3 participants