#2494·systemjs

Auto import dependencies

Author: WTbohdanoCreated Aug 23, 2024Updated Sep 3, 2025
  • SystemJS Version: 6.8.3 | 6.15.1
  • Which library are you using?
    • system.js
    • s.js
    • system-node.cjs
  • Which extras are you using?
    • AMD extra
    • Named Exports
    • Named Register
    • Transform
    • Use Default
    • Global
    • Dynamic Import Maps
  • Are you using any custom hooks? No

Question

I have an issue with auto import logic. I have storybook which is configured to a library type system. It automatically loads the systemjs like output bundle. SystemJS has document readyState check, in case loading it would add module to a autoImportCandidates. Later on its used in a instantiate logic, so it skip module load. Because of it, getRegister is not executed and last register is not reset. It leads to a wrong dependency resolution of the first dependency of a module.

Example:

javascript
System.register(['react', 'react-dom'],  () => {...})

First module dependency react has a dependency ['react', 'react-dom']

Workaround

Im hacking auto import logic, manually calling getRegister to reset lastRegister

javascript
const SystemJSPrototype = System.constructor.prototype;
const register = SystemJSPrototype.register;

SystemJSPrototype.register = function() {
  register.apply(this, arguments);

  if (document.readyState === 'loading') {
    SystemJSPrototype.getRegister();
  }
}

Sumarry

Is it expected behavior ? I guess lastRegister should be reseted on auto imported modules as well. It could be done right once autoImportCandidates is reseted.