question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browserify writes the following code to each output bundle to ensure compatibility with AMD, CommonJS and traditional globals:

    if ("object" == typeof exports) module.exports = e();
    else if ("function" == typeof define && define.amd) define(e);
    else {
        // global stuff...
    }

My problem is that I exclude some external libraries from my bundle (like react for example). Since the target system for my bundle is an AMD application, what I want browserify to generate is the following: (note the extended define clause)

    if ("object" == typeof exports) module.exports = e();
    else if ("function" == typeof define && define.amd) define(["react"], e);
    else {
        // global stuff...
    }

This does not seem to be possible at the moment.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sprilukincommented, Feb 23, 2016

@zertosh

Ok, a little bit more explanation.

default AMD module definition with dependencies should looks like

define(['dep1'], function(dep1) {
   //do something with dep1 which is already available at this point
});

this code will not work almost all the time since dependency most likely is not yet loaded (which is what we currenlty have with browserify):

define([], function() {
   return require('dep1'); //exception will be here because dep1 is not synchronously available at this point
});

But the following code will works as expected!!! (this is what we want browserify to do):

define(['dep1'], function() {
      return require('dep1'); //works ok since dependency is already available synchronously
});

I see that changes should be done not only in browserify.js. UMD template is part of umd library and it looks like:

var templateSTR = "(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}defineNamespace()}})(function(){source()});";

So in order to pass dependencies to define([],f) changes in this template should be done and UMD lib should allow to fill these dependencies.

After these changes browserify should leverage them and pass dependencies which user specified by --external parameter to UMD so template will incorporate them and produce correct umd header.

0reactions
zarlinkcommented, Nov 21, 2018

Hi, a simpler solution can be: before load our bundle, execute this simple snippet:

(function() { if (typeof define === "function" && define.amd) { define.amd= false; } })(); and then everything will work without problems. Although is a temporary solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix CommonJS or AMD dependencies can cause optimization ...
When you use a dependency that is packaged with CommonJS, it can result in larger slower applications. Starting with version 10, Angular now ......
Read more >
Angular warning: CommonJS or AMD dependencies ... - GitHub
Hi, I use this amazing library with the angular project. However the Angular warning displays with the following message: Warning: .
Read more >
WARNING CommonJS or AMD dependencies can cause ...
Resolve WARNING CommonJS or AMD dependencies can cause optimization in build ANGULAR 10.
Read more >
CommonJS or AMD dependencies can cause ... - YouTube
Angular.json CommonJS or AMD dependencies can cause optimization bailouts.
Read more >
Adding custom AMD modules - IBM
On the Behaviorr page of the view, select AMD dependencies. · Click Add and then specify the following information: In the Module ID...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found