maxulyanov / ImageComparison

Slider to quickly compare two images
https://m-ulyanov.github.io/image-comparison/
MIT License
59 stars 9 forks source link

Transpiling to ES5 causes Uncaught TypeError #3

Open skyclb opened 4 years ago

skyclb commented 4 years ago

Dear Ulyanov,

I want to thank you for creating this module, i do like it very much because of its lightweight size and simplicity. I recently used it for the first time and unfortunately encountered an js error when running under production mode.

I am using a gulp js minifier module which only accepts ES5, thats why i recognized your plugin been shiped as ES6 source. I did point my babel to transpile it to ES5 which worked without any error inside my dev setup. But then in the console i got the following error on this line:

if (typeof define === 'function' && define.amd) {
    define('ImageComparison', [], function() {
        return ImageComparison;
    });
} else {
    root.ImageComparison = ImageComparison;
    ^ Uncaught TypeError: Cannot set property 'ImageComparison' of undefined
}

I did double check my setup for causes, without success. Also i use two other npm modules shipped in ES5 which work perfectly. Removing the causing js block from your plugin does fix the error but corebreaks your module.

While searching your github, npm and examples page, i recognized that your example pages source js differs to the one in your github repo.

I hope to hear soon from you, i am out of ideas...

Best regards

skyclb commented 4 years ago

I did create a fiddle where you can reproduce it. Just check the console log.

https://jsfiddle.net/zhxr8k7j/1/

Best regards

BehringBOB commented 3 years ago

heyho @skyclb I also had problems when trying out the latest version.

The example page shows another version, you can download here. I just stayed with using this version and had no problems.

Anyway, I also like the script a lot because its touchfriendly and leightweight.