toddmotto / echo

Lazy-loading images with data-* attributes
http://toddmotto.com/labs/echo
3.72k stars 504 forks source link

root.addEventListener is not a function #121

Open mr-xiao opened 6 years ago

mr-xiao commented 6 years ago

root.addEventListener is not a function

kentjas1 commented 6 years ago

I'm also running into this issue when I am updating my app to use Webpack. I am using the ES6 import to include the npm package I installed.

import echo from "echo-js";
zlokomatic commented 5 years ago

Also got this issue not using es6 import but with webpack

pierre-dickinson commented 4 years ago

Hi @zlokomatic @kentjas1 I have the same issue with webpack. What is the solution ?

toddmotto commented 4 years ago

@pierre-dickinson It's probably due to this and webpack bundling in 'strict mode' as this may be undefined and therefore throw an error as addEventListener won't exist:

https://github.com/toddmotto/echo/blob/master/dist/echo.js#L12

You can change the this to window and that should solve it.