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

v6 loading module in importmap twice #2349

Closed
viT-1 opened this issue Jul 14, 2021 · 2 comments · Fixed by #2352
Closed

v6 loading module in importmap twice #2349

viT-1 opened this issue Jul 14, 2021 · 2 comments · Fixed by #2352

Comments

@viT-1
Copy link

viT-1 commented Jul 14, 2021

Demonstration

demo with v5, which is ok, have two messages in console:
SystemJS bundle file loaded!
Nice to see you, world

Actual Behavior

When I update package to latest version (6.10.2) and run scripts:
npm run deploy
npm run www

In browser (http://localhost:3000/) I have doubled message:
Nice to see you, world _bundle-system.js 48:21_
SystemJS bundle file loaded! _index.js:6:12_
Nice to see you, world _bundle-system.js 48:21_

@joeldenning
Copy link
Collaborator

I cloned the repo and saw the behavior. The problem is that in systemjs@5, loading a bundle with named registers via System.import resulted in the bundle module being an empty no-op, but in systemjs@6 we return the last named register in the file. So in the example code, System.import('bundle') is resolving with an empty placeholder module in systemjs 5 but the app module in systemjs 6.

This is a bug in systemjs that we should fix, but as a workaround you can add "app": "/bundle-system.js" to your import map and that fixes it. Also, another workaround is to just call System.import('bundle') rather than calling both System.import('bundle') and System.import('app').

I'll have to think more about what a fix would look like for this - the systemjs registry usually ensures no duplicate instantiation by resolving all specifiers to URLs and then only instantiating the module for each url once. Named modules violate this by inserting modules into the registry that do not have URLs associated with them. Ideally, we'd somehow connect the named register name with the bundle URL, although it's not clear how that would happen. Another approach could be to mark the registration arrays to avoid double instantiation or something along those lines (a bit ugly).

@joeldenning
Copy link
Collaborator

Fix released in https://github.com/systemjs/systemjs/releases/tag/6.10.3

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

Successfully merging a pull request may close this issue.

2 participants