arronhunt / highlightjs-copy

📋❇️ A simple, accessible highlightjs plugin to add a copy button to your code blocks.
https://highlightjs-copy.netlify.app
The Unlicense
101 stars 24 forks source link

Uncaught ReferenceError when importing in browser environment #16

Closed MohHeader closed 1 year ago

MohHeader commented 1 year ago

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:

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.

Vrejf commented 1 year ago

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

inkeytech commented 1 year ago

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:

reminia commented 1 year ago

same issue, downgrade to 1.0.3.

arronhunt commented 1 year ago

@MohHeader please confirm 1.0.5 resolves this issue

MohHeader commented 1 year ago

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

Thanks