How does SystemJS support multiple versions of the same library?

123 views
Skip to first unread message

Clint

unread,
May 9, 2016, 2:28:57 PM5/9/16
to SystemJS
I'm working on a jspm/systemjs app and would like to better understand how SystemJS handles multiple versions of the same dependency. Consider the following (simplified) SystemJS config example:

map: {
  "react": "npm:re...@0.14.8"
  "npm:foo": {
    "react": "npm:re...@0.14.7"
  }
}

I assumed when my code imported react it would get v0.14.8, while code in the "foo" dependency would receive v0.14.7. However, my browser console prints warnings about multiple copies of react being found.

Questions:

1. How does SystemJS supports multiple versions of dependencies,
2. Why would I be receiving an error like this if the different versions are kept separate?

Thanks!

Guy Bedford

unread,
May 15, 2016, 7:22:57 PM5/15/16
to Clint, SystemJS
In jspm each version of a package has a unique URL so SystemJS knows where to find it. In the case of react this is jspm_packages/npm/re...@0.14.8/... Then every piece of code is executed as a module so that we avoid using globals as far as possible and can control what version a reference to `import 'react'` gets normalized into, exactly like in the map example you posted which allows using jspm_packages/npm/re...@0.14.7/... instead.

But it is still possible for modules to define globals themselves, and have state. So some libraries won't support multi-version support at all, React being one of those.

In this case React is a peer dependency - a library that should always be deduped to an exact version due to this constraint. Large framework libraries usually make sense to treat as peer dependencies.

--
You received this message because you are subscribed to the Google Groups "SystemJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to systemjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages