-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Warning about wrapShim with RequireJS #1574
Comments
I'm a bit confused. We just added the define("moment", function (require, exports, module) {
if (module.config && module.config() && module.config().noGlobal !== true) {
// If user provided noGlobal, he is aware of global
makeGlobal(module.config().noGlobal === undefined);
}
return moment;
}); If that is not the case then we have a bug. |
That's why I was confused at first also! The global is exported... but too late! The issue is that the RequireJS optimizer r.js (by design) concatenates all your modules into 1 file, in the order required based on dependencies. However, the actual execution of the code is a little different. The raw JS file will be parsed and the non-AMD plugins that rely on AMD plugins will throw an error.
with wrapShim it's something like:
The
So in summary, the design decision you've made is fine, but I suggest pointing out the |
Leaking the global right away would prevent us from using the |
Such a mess... Lets fix the docs. |
Lets also export the global in the beginning. |
Fixed by #1590. |
I've got a pretty large project using many plugins for jquery, bootstrap, backbone, etc. Upon upgrading to the latest moment.js some non-AMD-compatible plugins that depended on moment (e.g. bootstrap-daterangepicker) stopped working -- only in the r.js optimized single-file build of the project.
The issue is due to how (later versions of) Moment don't also set a global window.moment if RequireJS is present. What moment.js is doing is pretty unique among browser RequireJS libraries (first I've encountered). jQuery still exposes the global even when RequireJS is used.
Even when you define the RequireJS shim properly, such as:
shim: { 'bootstrap-daterangepicker': ['jquery', 'moment'] }
it still fails.There is a RequireJS option wrapShim that fixes this behavior.
I bring this up only because it took me a long time to debug the issue (for what should have been a simple Moment.js version bump), so I'd recommend putting a warning in http://momentjs.com/docs/#/use-it/require-js/ like:
The text was updated successfully, but these errors were encountered: