arronhunt / highlightjs-copy

📋❇️ A simple, accessible highlightjs plugin to add a copy button to your code blocks.

Home Page:https://highlightjs-copy.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught ReferenceError when importing in browser environment

MohHeader opened this issue · comments

commented

Hello @arronhunt,

I've encountered an issue while using the 'highlightjs-copy' library on my non-Node.js website. I'm loading the library as instructed in the README file:

<script src="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js"></script>

However, doing so leads to an error in the console:

Uncaught ReferenceError: module is not defined
https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js:1

It seems the library is utilizing the Node.js module.exports syntax, which isn't supported in a browser environment, causing the ReferenceError.

I believe this issue surfaced after the latest 1.0.4 update. Before this update, I didn't encounter such an issue.

Thank you for your time and consideration.

I get the same error
Uncaught ReferenceError: module is not defined
Uncaught ReferenceError: Cannot access 'locales' before initialization

Hello,
I do believe that version 1.0.4 introduced an issue.
I've been pulling highlightjs-copy from the CDN in a project I'm currently actively working on.
The moment version 1.0.4 was placed on the CDN, I started to receive the issues mentioned above.
I'm currently working around it using the following to retrieve the file from the CDN: <script src="https://unpkg.com/highlightjs-copy@1.0.3/dist/highlightjs-copy.min.js"></script>

same issue, downgrade to 1.0.3.

@MohHeader please confirm 1.0.5 resolves this issue

commented

@arronhunt, yup it is working now, I am really grateful for the fix.

Thanks