Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError with RequireJS #22

Open
fabiocaseri opened this issue Feb 12, 2014 · 11 comments
Open

Uncaught TypeError with RequireJS #22

fabiocaseri opened this issue Feb 12, 2014 · 11 comments

Comments

@fabiocaseri
Copy link

Switchery is not working for me when using RequireJS (v2.1.10).
It seems the problem is present since the introduction of FastClick library.
In console I get "Uncaught TypeError: object is not a function" at line 1311, doing some debugging I see that fastclick var is an empty object.

I've uploaded an example:
Preview: http://bl.ocks.org/fabiocaseri/8956655

Gist: https://gist.github.com/fabiocaseri/8956655

@abpetkov
Copy link
Owner

It appears when using requireJS, module.exports is not present (this if statement) and therefore an empty FastClick object is returned.

It seems that FastClick is not maintained very well, seeing their issues and pull requests, so I won't bother to fix that for them. I'll find an alternative to use and replace this dependency. Until then, apply some temporary fix so that the FastClick.attach method is attached to module.exports and watch for further update on this issue from me.

@infacq
Copy link

infacq commented Jun 26, 2014

looking forward for requireJs

@chandra-sekar
Copy link

Hi, any updates on this? Some more info on how to apply the temporary fix will be very useful. I am trying to use this on a backbone project. Thanks for the library.

@ingro
Copy link

ingro commented Sep 4, 2014

@chandra-sekar
A quick fix for the problem would be:

  • go to switchery.js file in the dist folder and search for FastClick.attach function.

Few lines below, change this if statement from

if (typeof define !== 'undefined' && define.amd) {

    // AMD. Register as an anonymous module.
    define(function() {
        'use strict';
        return FastClick;
    });
}

to

if (typeof define !== 'undefined' && define.amd) {

        // AMD. Register as an anonymous module.
    module.exports = FastClick.attach;
    module.exports.FastClick = FastClick;
}

Not the prettier solution but it works.

@chandra-sekar
Copy link

@ingro
I somehow missed your reply. I had reverted to using an old version of switchery (pre-fastclick). I have now switched over to the new version using your fix. Thanks a lot!

@charlessolar
Copy link

+1 for a permanent fix, editing the file all the time is a pain

@bartzy
Copy link

bartzy commented Mar 10, 2015

@abpetkov , Do you plan to fix this issue?
Without the change proposed by @ingro, Switchery cannot be used with RequireJS.

Thanks!

@bartzy
Copy link

bartzy commented Mar 11, 2015

@abpetkov
After some further researched, I don't think this is fastclick's problem.
For example, Hammer.js, which is well maintained, is behaving in the same wayif you include them as a ComponentJS dependency.

What happens is the following:
Somewhere in a library (such as Fastclick or Hammer.js for example), there is something like this:

if (typeof define !== 'undefined' && define.amd) {
    // AMD. Register as an anonymous module.
    define(function() {
        'use strict';
        return FastClick;
    });
} else if (typeof module !== 'undefined' && module.exports) {
    module.exports = FastClick.attach;
    module.exports.FastClick = FastClick;
} else {
    window.FastClick = FastClick;
}

When your code uses FastClick as a Component module, it concatenates this code as part of the FastClick module. When this code runs in a RequireJS environment, it defines a RequireJS anonymous module, but the file name is switchery.js and not related to fastclick, so RequireJS gets totally confused.

Do you have any direction on how to approach fixing this? I know this is not directly related to Switchery.

@jakeorr
Copy link

jakeorr commented Apr 28, 2015

+1 for requirejs support

@vedmant
Copy link

vedmant commented Apr 19, 2017

It looks like this problem is still there, it's just not working with Webpack, still no permanent solution without editing packages file for this?

@adiploma
Copy link

define() is being invoke multiple times:

  • the first one is to define the Switchery
  • the second is to define the FastClick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants