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

registration[1] is not a function #2192

Closed
2 of 8 tasks
yln99517 opened this issue May 17, 2020 · 5 comments
Closed
2 of 8 tasks

registration[1] is not a function #2192

yln99517 opened this issue May 17, 2020 · 5 comments

Comments

@yln99517
Copy link

  • SystemJS Version: 6.3.1
  • Which library are you using?
    • SystemJS - 6.3.1
    • SJS
  • Which extras are you using?
    • AMD extra
    • Named Exports
    • Named Register
    • Transform
    • Use Default
    • Global
  • Are you using any custom hooks?

Question

I am using typescript outfile with systemJS.
registration[1] is not a function
I followed #1886 but still having the problem.
Repo details - https://github.com/yln99517/MyMathLib
you can try here - https://yln99517.github.io/MyMathLib/

@joeldenning
Copy link
Collaborator

Note that this is a duplicate of #2185. I will try to take a look at this later.

@joeldenning
Copy link
Collaborator

I am looking at this now. This is due to race conditions / timing issues in the named-register extra. Your code works in systemjs@6.2.5, but not in >=6.2.6. The reason is that in 6.2.6 we switched from a full tick of the event loop (setTimeout task) to a microtask within the event loop (Promise.resolve) for resetting the firstNamedDefine variable. You can read more about that at #2144, #2139, and #2138.

The named-register extra has had a history of being buggy and having timing issues. Over the last year, there have been a variety of efforts to fix it:

Due to this long history of painful bugs, we've started encouraging people not to use the named-register extra if they can avoid it. In typescript, this can be done by switching from outfile to outdir inside of the tsconfig.json, which changes typescript from outputting a single bundle file to outputting multiple files.

That said, even though named-register is generally discouraged, we still support it. I have worn myself out trying to fix that extra in the last year with several dozens of hours that still haven't resulted in the extra fully functioning, and do not plan on spending more time on it. So I'd appreciate community help on this.

@yln99517
Copy link
Author

@joeldenning , thanks for the quick response. Can you suggest me a good bundler for SystemJS files that are generated by typescript outDir format?. I tried rollup, but I think it doesn't understand files which "system.register" format.

@joeldenning
Copy link
Collaborator

Rollup works very well - webpack works as well. Here are the options I'd consider:

  1. No bundler, just typescript outdir. This will produce one output file per source file, and SystemJS will load each of the output files as a network request. This is completely fine and is the least amount of change to your project.
  2. Use rollup/webpack instead of typescript to compile/bundle the code. When using these, you'd run rollup -c instead of tsc to generate the bundle file. This will produce a single output file that is in System.register format.

You mentioned some confusion about the System.register format - it is a way of representing import and export without using the import/export keywords. You do not need to write it manually - typescript, rollup, and webpack all know how to generate it for you.

@yln99517
Copy link
Author

thank you. closing the issue

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