Full version of lodash now available in the SharePoint Framework

Jan 3, 2018

TL; DR;

Microsoft replaced @types/es6-collections by the es2015.collection library in version 1.4.0 of the packages. Those had a conflicting definition of weakmap which caused issues with packages like lodash.

Long version

Microsoft recently release v1.4.0 of the SharePoint Framwork and it’s packages. It contains a lot of improvements and one of those probably went unnoticed by many of us.

@types/es6-collections has been replaced by es2015.collection library (native, comes with the compiler/JS Engines). That package had a “special” definition of WeakMap (among other things) which was causing numerous packages not to work properly, include one of my favorites: lodash.

To workaround that issue, Microsoft had to provide @microsoft/sp-lodash-subset which as it name indicates, is only a subset of lodash and didn’t provide useful methods like map.

Which one should I use?

This is something that’s hard to say at the moment, I’ll give you the pro’s and con’s instead for using the subset

Pro’s:

  • The subset is lighter, which means faster load times for your users
  • The subset is maintained/checked by Microsoft, which means less likely to break SPFX

Con’s

  • The subset doesn’t have all the lodash features, which means you might have to do more things manually
  • The subset is maintained by Microsoft, which means improvements in lodash won’t get to us as fast
  • The subset is not on a CDN, which can impact your load times depending on a lot of other considerations (HTTP2, quality of your CDN…)
  • The subset might not be around for long, considering it represents extra work for Microsoft, they might deprecate it to focus on other things

Now all that being said, nothing prevents you from using both in parallel and the upgrade path (from subset to full version) is fairly easy once you’re on SPFX >= 1.4.0: it’s about a couple of text replace.


Last edited Apr 15, 2024 by Vincent Biret


Tags: