-
Notifications
You must be signed in to change notification settings - Fork 122
Support building anonymous + named define AMD modules #337
Comments
Named defines do not support bundling as they are already bundles. I would suggest ensuring you bundle anonymous defines. |
@guybedford that's sad: I have to create 4 more files for uncommon use. Ideally I'd like to see an error or warning about bad logic when I use client-side SystemJS. There are too many differences between builder and SystemJS, it's annoying. |
@finom certainly we could construct a suitable error message in this case. |
@guybedford it looks like there is a bug. define(function() {
return 'foo';
});
define('bar', function() {
return 'bar';
});
define('baz', function() {
return 'baz';
}); But still getting "Uncaught Module 2 not present." |
@finom yes we do not support loading mixed bundle and anonymous modules like that. If you run it dynamically with SystemJS in the browser you should get a better error message. |
@guybedford but what should I do with libraries which use the same logic (one default definition and some named definitions). One weird thing for me is that library is included in a bundle but don't work. |
Try ensuring that all the defines are named to load it as a bundle and then require the name you want after loading the bundle. Alternatively, use the version of the library that loads as a proper module. |
Sorry, I don't know what do you mean. Can you give me an example or a link? Do you mean I need to use 2 files on a page (bundle + library)?
It sounds like you think that this is not a bug. Requirejs + r.js optimizer works with such stuff very well. |
If I understood correctly, if one of the files contains named definition (eg for internal purpose), the builder will not work. Which means the builder doesn't work with named definitions at all, right? |
Ugh. I've tried to fix this by removing named modules but it still throws "Uncaught Module 2 not present.". Then I've removed all library code and kept only UMD stuff and there was no error. UPD: #344 |
I've fixed it by this hacky trick: var d = "define";
define(function() {
return 'foo';
});
if(__root[d]) {
__root[d]('bar', function() {
return 'bar';
});
__root[d]('baz', function() {
return 'baz';
});
} It's fine because I can make changes to my library. In other libraries anonymous+named modules will not work. |
This has been implemented and released in Released in 0.15.10. |
After I've built the project via
buildStatic
I've got an error in JS file:What I am trying to do is to include to the project a source of MatreshkaJS framework. Config:
File lib/matreshka/matreshka contains definitions of named modules:
There isnot anonymous module definition. After all I can import named modules by the app:
It works great in development. But after compile I'm getting the error described above. The module 'lib/matreshka/matreshka isn't presented in resulting file.
I tried to modify lib/matreshka/matreshka by adding anonymous definition:
And this module appeared in compiled JS but I've got almost the same error:
This logic worked fine with RequireJS builder.
I hope somebody looks at the issues.
The text was updated successfully, but these errors were encountered: