cookieconsent icon indicating copy to clipboard operation
cookieconsent copied to clipboard

[Bug]: esm version has no cookieConsent variable

Open ourmaninindia opened this issue 1 year ago • 1 comments

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/[email protected]/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 avatar Feb 29 '24 21:02 ourmaninindia

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 avatar Feb 29 '24 22:02 orestbida

Same issue here after importing

import CookieConsent from 'vanilla-cookieconsent';

I get this error: image

dreinon avatar Mar 13 '24 00:03 dreinon

@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';

orestbida avatar Mar 13 '24 19:03 orestbida

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

dreinon avatar Mar 13 '24 20:03 dreinon

image

dreinon avatar Mar 13 '24 20:03 dreinon

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 avatar Mar 13 '24 22:03 orestbida

I agree with you.

On Wed, 13 Mar 2024, 23:20 Orest Bida, @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/orestbida/cookieconsent/issues/656#issuecomment-1995990920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKPJ2HCBMZOXWY5S5SUOTYYDGLZAVCNFSM6AAAAABEAW234OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJVHE4TAOJSGA . You are receiving this because you were mentioned.Message ID: @.***>

ourmaninindia avatar Mar 14 '24 10:03 ourmaninindia