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

Requiring Node modules that support AMD causes them to try to expose themselves as AMD #398

Closed
stevenpetryk opened this issue Mar 28, 2015 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@stevenpetryk
Copy link

Most Node packages expose themselves via AMD, CommonJS (module.exports), or globals depending on the environment. I understand that React-native does indeed support AMD, but is there any way to force modules to be treated as CommonJS?

Steps to reproduce:

  1. Create a new React Native project

  2. Run npm install exoskeleton (this, along with jsSHA, are the first two libraries I noticed this with)

  3. Add the following to index.ios.js:

    var Exoskeleton = require('exoskeleton');
    console.log(Exoskeleton);
  4. Notice how, in the debug console, an empty object is logged.

@stevenpetryk
Copy link
Author

To add to this, if one goes into Exoskeleton's source, and adds the following (at the top of the file, starting at line 10):

(function(root, factory) {
  // Set up Backbone appropriately for the environment.
  if (typeof define === 'function' && define.amd) {

    console.log('Using AMD'); // <----------------- ADD THIS

    define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
      root.Backbone = root.Exoskeleton = factory(root, exports, _, $);
    });
  } else if (typeof exports !== 'undefined') {
    var _, $;
    try { _ = require('underscore'); } catch(e) { }
    try { $ = require('jquery'); } catch(e) { }
    factory(root, exports, _, $);
  } else {
    root.Backbone = root.Exoskeleton = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
  }

You will see Using AMD! logged to the console.

@novadev94
Copy link

This also happens with lodash. Using the same test method by @stevenpetryk. Insert console.log('Using AMD'); to line 11776 of lodash/index.js:

  // Export lodash.
  var _ = runInContext();

  // Some AMD build optimizers like r.js check for condition patterns like the following:
  if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
    console.log('Using AMD');

@vjeux
Copy link
Contributor

vjeux commented Mar 28, 2015

Thanks for investigating. @amasad will investigate why we have define as a global when he gets a chance

@novadev94
Copy link

I think it's probably related to #406

@vjeux
Copy link
Contributor

vjeux commented Mar 29, 2015

Closing this one, #406 is tracking it.

@vjeux vjeux closed this as completed Mar 29, 2015
@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants