mapbox / pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
ISC License
6.1k stars 304 forks source link

CDN script error: module not defined #134

Closed derek-ye closed 2 months ago

derek-ye commented 6 months ago

Description

I'm trying to embed the script in a static HTML file, but I'm running into the following error. I think it might be due to the script being a CommonJS module - any ideas on how I could fix this without converting the entire file to ESM?

index.js:3 Uncaught ReferenceError: module is not defined
    at index.js:3:1
(anonymous) @ index.js:3

HTML file:

<body>
    <script src="https://cdn.jsdelivr.net/npm/pixelmatch@5.3.0"></script>
    ...
mourner commented 6 months ago

Yeah, looks like we need to convert Pixelmatch to ESM to use it on the browser properly now. Meanwhile, as a workaround, maybe you could try using Skypack CDN which does CommonJS to ESM convertion automatically: https://cdn.skypack.dev/pixelmatch

mourner commented 2 months ago

pixelmatch v6.0.0 is now a module, so this should be fixed.