enquire.js icon indicating copy to clipboard operation
enquire.js copied to clipboard

enquire is undefined

Open asecondwill opened this issue 6 years ago • 6 comments

I'm having some trouble with this. I've included it using import via gulp / webpack. the enquire.js code gets included in my main.bundle.js file above the code that references it.

Then, when I try to use it, enquire.default.register("screen and (max-width:560px)", {

I get error

enquire is undefined

What have I done wrong?

asecondwill avatar Mar 07 '18 15:03 asecondwill

I am also having this issue, "enquire is not defined".

My code is similar to the example codes:

enquire.register("screen and (max-width: 769)", {
        match: function() {
          // code
        },
        unmatch: function() {
          // code
        }
    })

note: I am trying to use enquire in React

oliviam20 avatar Jun 13 '18 03:06 oliviam20

The same thing here. I've tried to import as follows:

import {enquire} from "/node_modules/enquire.js/dist/enquire.js"

bsvTag avatar Jun 15 '18 17:06 bsvTag

Did anybody find any solution to this issue?

fogpuddle avatar Feb 06 '19 15:02 fogpuddle

Not ideal but you can use provide plugin:

const webpack = require('webpack');
environment.plugins.append('Provide', new webpack.ProvidePlugin({
  enquire: 'enquire.js/src/index.js',

}));

module.exports = environment

thomasdarde avatar Oct 08 '19 14:10 thomasdarde

For reasons I can't quite recall, the main field of package.json is set to ./src rather than the ./dist/enquire.js. So currently, you should be able to import enquire like this:

import enquire from "enquire.js/dist/enquire";

Here's a working example: https://codesandbox.io/s/naughty-bash-9q0og. To test you'll need to open this and resize your window: https://9q0og.csb.app/

WickyNilliams avatar Oct 08 '19 14:10 WickyNilliams

Actually, I take that back, I can import enquire.js directly, as seen here: https://codesandbox.io/s/adoring-cloud-rfncs

import enquire from "enquire.js";

WickyNilliams avatar Oct 08 '19 14:10 WickyNilliams