Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Load dependencies based on the format of the parent #883
Expanding on #333. I've had several issues opened on my packages from users having trouble using Webpack with my packages, even though I support Browserify/RequireJS/UMD with all dependencies. See desandro/masonry#679 and metafizzy/packery#239.
Package authors are set on a collision course with UMD and Webpack. Authors are encouraged to support both AMD and CommonJS exports, adhering to UMD. Ideally, when you adhere to a community specification, things should work out of the box, without requiring users to add extra config or authors to re-tool their source for your loader.
My recommendation is that Webpack should load dependencies based on the format of the parent. For example:
When you load
The current solution is use
Hmm I don't think it's so simple. The style of the parent is not relevant, the package manager (npm or bower) is. If a user likes to write AMD, but installs modules via npm this will break.
You assume that modules installed via npm always use CommonJs and modules installed via bower always use AMD. But with webpack this is not true anymore. Both styles can be used for both package manager. I see that this leads to an issue.
The cleanest solution would be to publish different modules to npm and bower. Each one only with the correct dependencies for the package manager. But this lead to an overhead. (I would do it this way: write your module in CJS, publish it to npm and use webpack to compile an UMD version for bower ;), this way you could split your modules into multiple files )
Here are some workarounds which would eliminate the configuration by the user:
Yeah, but this is not correct. If you write your code in AMD you may still want to require a CommonJs module from npm. Of if you write your code in CommonJs you may still want to require a AMD module from bower...
@sokra is there a way to change the loader order so that CommonJS is always checked first?
I'm having an issue which seems related to this one in the fact that I'm using exoskeleton without jquery. While jquery is not a requirement, it is a dependency from an amd standpoint (but not necessary from a CommonJS standpoint)
AMD jquery dependency
Why it is not necessarily required
This was referenced
May 12, 2015
2 similar comments
1 similar comment
referenced this issue
Dec 28, 2015
referenced this issue
Dec 31, 2015
@homerjam: That would not solve the issue here. This issue occurs when Webpack loads a UMD module that successfully resolves AMD. The problem is loading such a module from a CommonJS context still gets the AMD version since that's the first available from the UMD wrapper.
I don't think this is necessarily a problem of webpack, but rather other packages (and as far as I see most of them are from @desandro) who assume that AMD === bower/requirejs/... and CJS === npm/node/..., which is not correct, as with all the browser-bundlers, both ways can be used in different ways.
I think this is the best solution.