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

Error/Bug when loading multiple modules in register format from same file #1262

Closed
niabot opened this issue May 9, 2016 · 3 comments
Closed

Comments

@niabot
Copy link

niabot commented May 9, 2016

Lets say i have tiny library file in the es5 system/register format named 'foo.js'. It contains two modules. The first is called 'foo', the second is called 'foo/bar'.

The Javascript Code inside foo.js is organized as follows:

System.register("foo", ["foo/bar"], function(exports_25, context_25) {
...
}
System.register("foo/bar", [], function(exports_13, context_13) {
...
}

To use this library in a secondary project i wrote the following config.js so that both modules will be loaded from the same file:

System.config({
    paths: {
        '*': '*.js'
    },
    map: {
        'foo': 'foo'
        'foo/bar': 'foo'
    }
});

If i now try to load a class from 'foo/bar' like

import {SomeClass} from 'foo/bar';

then i get the following error message:

Uncaught Error: Multiple anonymous System.register calls in module http://localhost:8383/lib/foo.js. If loading a bundle, ensure all the System.register calls are named.
(anonymous function)@system.js:2916
loader@system.js:3591
loader.amdDefine@system.js:4075
complete@system.js:2716

So i wonder what would be the problem. All modules in foo.js are obviously named.

      // anonymous register
      if (!entry.name || load && entry.name == load.name) {
        if (!curMeta)
          throw new TypeError('Unexpected anonymous System.register call.');
        if (curMeta.entry) {
          if (curMeta.format == 'register')
            throw new Error('Multiple anonymous System.register calls in module ' + load.name + '. If loading a bundle, ensure all the System.register calls are named.');
          else
            throw new Error('Module ' + load.name + ' interpreted as ' + curMeta.format + ' module format, but called System.register.');
        }
        if (!curMeta.format)
          curMeta.format = 'register';
        curMeta.entry = entry;
      }
@niabot
Copy link
Author

niabot commented May 9, 2016

I guess this can be closed. The error message throw me off. But i guess that is what bundles is for.

@guybedford
Copy link
Member

I think I may have made this case work in cb71254, as in theory it shouldn't be giving this error... but yes it is an edge case when the bundle name is the defined name inside the bundle.

If you can test it out though when the next release comes, do let me know if that helps.... I can post a note here when that happens.

@guybedford
Copy link
Member

Released in 0.19.28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants