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

Viewed 1431

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.

2 Answers

So it turns out it's the js-cookie's most recent release that broke things.

I posted the issue on their github repo and got a work around, until they solve this issue in their latest release:

https://github.com/js-cookie/js-cookie/issues/698

Elte156 said that to use this earlier version for now, until the breaking change resolves:

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

I can confirm that this work around works for me.

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

Related