modernizr-loader icon indicating copy to clipboard operation
modernizr-loader copied to clipboard

Uncaught TypeError: _modernizr2.default.mq is not a function

Open sonarforte opened this issue 7 years ago • 2 comments

I'm using the exact configuration as specified in the Readme, and the import of Modernizr works.

However, when I go to use the thing, I get the error Uncaught TypeError: _modernizr2.default.mq is not a function.

Here is my modernizr config:

{
  "minify": true,
  "options": [
    "setClasses",
    "mq"
  ],
  "feature-detects": []
}

When I use mq, I get the error above. Here is my code:

import Modernizr from 'modernizr'
...
var query = Modernizr.mq('screen and (max-width: 600px)')

Incidentally, if I print out the Modernizr object, I get this:

{
  "minify":true,
  "options": ["setClasses","mq"],
  "feature-detects":[]
}

Where it's quite obvious that mq is not even a direct descendant, let alone a function.

However, this is what the docs say to do, so what gives?

sonarforte avatar Jul 10 '17 06:07 sonarforte

For @sonarforte and others that had this issue

In my case i had to check if Modernizr.mq exits because this method exitis only on client side, not on server side.

So something like:

import Modernizr from 'modernizr'
if (Modernizr.mq) {
  var query = Modernizr.mq('screen and (max-width: 600px)')
}

adam187 avatar Jan 31 '18 09:01 adam187

You have a modernizr configuration included in your code instead of modernizr itself. It means that loader isn't configured correctly. Need to look at your config to see what's wrong.

arusak avatar Sep 04 '18 07:09 arusak