modernizr-loader
modernizr-loader copied to clipboard
Uncaught TypeError: _modernizr2.default.mq is not a function
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?
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)')
}
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.