WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.62k stars 269 forks source link

matchMedia polyfill stopped working with latest release #161

Closed SiqiTian-minted closed 7 years ago

SiqiTian-minted commented 7 years ago

Hi, we have saw this new error started today:

/local/workspace/minted_ui-test/node_modules/enquire.js/dist/enquire.js:116
    if(!matchMedia) {
        ^

ReferenceError: matchMedia is not defined

The polyfill for matchMedia does not work any more. https://github.com/WickyNilliams/enquire.js/issues/82

SiqiTian-minted commented 7 years ago

version 2.1.5

WickyNilliams commented 7 years ago

Can you give any more information? What is throwing that error?

EricFreeman commented 7 years ago

I'm trying to run mocha tests and I'm seeing the same issue as @SiqiTian-minted. My builds started breaking around 3pm mst yesterday but nobody touched anything related to this package.

WickyNilliams commented 7 years ago

Hmm it's odd that it's suddenly causing issues. I have made changes to this project in recent days, but that specific line has been the same for years.

Can you provide more details? A reduced test case, or a public repo i can pull and see it happening? Are you tests running in a headless browser? if so, have you tried stubbing out matchMedia?

uuid1017 commented 7 years ago

matchMedia is not define in node.js environment

m11m commented 7 years ago

matchmedia-polyfill will add it to window, in node this ends up being global.window

So in the browser, matchMedia is like a global, all scopes will eventually get to window. In node, NOT all scopes will go across window.

Looking at the code, I saw some places where it was referring to window.matchMedia. My guess is there are now some places that are only referring to matchMedia, and that will cause a problem running in node with polyfill.

afaik :)

sytong commented 7 years ago

Thanks @mattschlobohm for the suggestion.

I can now work around this problem by polyfilling matchMedia to both global.window and global.

WickyNilliams commented 7 years ago

So is there anything I can do to fix this? I'm still not sure why this would have suddenly broke

wwsun commented 7 years ago

Using enquire.js@2.1.1 @WickyNilliams

WickyNilliams commented 7 years ago

Should be fixed in v2.1.6. Thanks to @Edward67 for the PR!