orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js

Home Page:https://playground.cookieconsent.orestbida.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: esm version has no cookieConsent variable

ourmaninindia opened this issue · 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/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

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.

Same issue here after importing

import CookieConsent from 'vanilla-cookieconsent';

I get this error:
image

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

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

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.