Skip to content
This repository was archived by the owner on Mar 27, 2019. It is now read-only.
This repository was archived by the owner on Mar 27, 2019. It is now read-only.

Can't use Component modules with a RequireJS environment #627

Open
@bartzy

Description

@bartzy

Hi,

I'm trying to use a Component-based module (https://github.com/abpetkov/switchery) with a RequireJS environment.
I'm obviously using the dist/switchery.js files that I guess is called standalone in Component.

The thing is, Switchery depends on FastClick. Somewhere in the standalone dist JS file there is this code:

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;
}

I guess this is concatenated by Component from the FastClick lib itself.

The first if statement is executed of course (Since define exists because we use a RequireJS environment), and an anonymous RequireJS module is anounced.
The other statements (else if and else) are not executed of course.

This causes 2 major issues:

  1. When Switchery needs FastClick and executed require('fastclick'), Component's require function will return an empty Object since there is no module.exports for that at all. That of course breaks Switchery.
  2. RequireJS's define function now defined an anonymous module in a file that is not related in anyway to that module (FastClick). It wrecks havoc on the process of loading other RequireJS modules.

I gave Switchery as an example, but I believe this happens with all Component builds for modules that have dependencies, and used in a RequireJS environment.

Any input on this issue would be much appreciated!

Thanks,
Bar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions