SystemJS: A module loader for the browser
April 05, 2025

Last week i had a chance to work with single-spa (a framework to build micro-frontends), that's when i first see SystemJS as an option while i initialize single-spa with CLI, so my instinctive reaction is to google it.
What is SystemJS?
From their docs:
SystemJS is a hookable, standards-based module loader.
This is how i get it:
SystemJS is a module loader. it's easy as it sounds, it loads the module from the source, at RUN TIME.
Now the why?
After my long reading, the pain point was, when ES modules (ESM) were not widely supported on the browsers, this piece of code from the scenario below was not be able to run on the browsers.
The small scenario
Let's imagine this, you have an utils file utils.js, the main file main.js,
and you want to use the utils file in the main file, then load the main file
in the browser.
This code would not execute on the browser, since the browser can not understand
the import or export syntax (yes, it is now supported on most of the browsers,
but not all of them, and back to the time, it was not).
So, what's should we do?
Yes, we can not just give it up, let's take a quick look some solutions that the engineers could use back then.
Change it to CommonJs
So the widely used solution was transform this code from ESM to CommonJs.
Use Webpack to transpile the code
Another solution here, we can use bundler (here - Webpack, with the help of Babel) to convert the ESM to CommonJs with the following config:
then import the code in the browser with the following code:
Now the main dish: SystemJS
Soooooo, now we have the solution to load the code in the browser, but what if we want to use the ESM syntax with least effort?
and the code would be able to run on the browser, how cool is that?
Step a bit deep down to SystemJS
Not only from a file, also from a url
SystemJS not only can load the code from a file, but also from a url. Let's see an example:
Dynamic import
As usual, if we import a module, it will be loaded immediately, but what if we want to load the module dynamically, like lazy loading?
here, we can import the module at runtime, ondemand only the click event is triggered, and the module will be loaded when the promise is resolved.
My quick take
SystemJS is a powerful module loader, will be more insight to go during my single-spa journey.
Reference
Table of Contents