js-cookie: Using js-cookie on third party sites / noConflict

The bug happens in the following circumstance:

A site uses requirejs for loading js (called parent site). In this parent site third party javascript snippets are used. The third party scripts (i.e. js based polls, popups, counters, …) have no access to the requirejs loading environment of the parent site.

js-cookie is used in such a third party script. Because the third party script does not know in which environment js-cookie is loaded, they should use the noConflict method. That works well if the parent site does not use requirejs. However if the parent site uses requirejs, the noConflict method throws an error because it is not exported.

This issue is very similar to #234 .

Expected behavior js-cookie allows noConflict under all circumstances, even if the host site uses requirejs.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 35 (23 by maintainers)

Most upvoted comments

@carhartl Thank you for these tips. I think you are right, a separate build is needed.

Are you open to adding to the README, in the heading “Namespace conflicts” for version 3:

If you need to use js-cookie without using UMD modules in a page which uses UMD modules, you need to rebuild js-cookie with the rollup.config.js output format set to iife instead of umd. This usage might be necessary when you use js-cooke in a third party javascript application.

@unuseless You have an idea how to solve this?