javascriptjs-cookie

Firefox and Chrome error when linking js-cookie: Uncaught ReferenceError: module is not defined


Error in the console log: "Uncaught ReferenceError: module is not defined"
This is what is causing the error:

        <script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>

enter image description here

Does this happen to anyone else on Chrome and firefox? Does anyone have a solution?

This wasn't happening before, but started today.


Solution

  • Major releases of packages can shift around files. In this case the referenced file became a CommonJS module, which doesn't run directly in the browser. The good news is that many packages, including the new version of js-cookie, tell jsdelivr which file to use by default.

    If you use this url, everything should keep working: https://cdn.jsdelivr.net/npm/js-cookie@rc