-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Category
- Question
- Typo
- Bug
- Additional article idea
Expected or Desired Behavior
Importing ES6-Shim or Core.js/ES6 Shims for ES6 library support in SPFX.
Any suggestions as to how to integrate the necessary Polyfills into SPFX in general would be greatly appreciated. I have tried manually adding Polyfills for each issue but the existing libraries are thousands of lines long and have required years to develop. Recreating this functionality from scratch would be an exhaustive effort.
As a large share of modern libraries rely on ES6 and its polyfills. This issue greatly limits developer options. Angular 2+ and many other solutions require this functionality.
Observed Behavior
Polyfill libraries (ES6-Shim and Core.JS/ES6) work in other TypeScript based deployment scenarios, but throw 'Out of Stack Space' errors in SPFX.
https://github.com/paulmillr/es6-shim
https://github.com/zloirock/core-js
So far in my testing I've got the error down to these 2 polyfills. All of the other Angular requirements will load without issue.
import 'core-js/es6/map';
import 'core-js/es7/reflect';
map is the only Angular 2 requirement that's causing an issue in SPFX and the SP Loader has it's own map implementation for IE.
I have tracked the issue most of the way down into the sp-loader-assembly_en-us.js file on line 703 where it seems to rerun this loop until it crashes:
var queue = new Array(1000);
function flush() {
for (var i = 0; i < len; i += 2) {
var callback = queue[i];
var arg = queue[i + 1];
callback(arg);
queue[i] = undefined;
queue[i + 1] = undefined;
}
len = 0;
}
It also pops in and out of the eval in block 37 while it goes through this loop:
/* 37 */
/***/ (function(module, exports) {
(function (global) {
eval('/*\r\n * SystemJS v0.19.25......................................');
}.call(exports, (function() { return this; }())))
I have tried to step through the code until it finally dies but so far I haven't been able to track it that far. My thoughts at the moment are that this is a collision of type 'Map' which is defined globally in the SP-Loader and in the Core-JS polyfills.
sp-loader-assembly_en-us.js
if (typeof Map == 'undefined' || typeof((new Map).values) !== 'function' || !(new Map).values().next) { exports.Map = createCollection({ // WeakMap#delete(key:void*):boolean 'delete': sharedDelete, //:was Map#get(key:void*[, d3fault:void*]):void* // Map#has(key:void*):boolean has: mapHas, // Map#get(key:void*):boolean get: sharedGet, // Map#set(key:void*, value:void*):void set: sharedSet, // Map#keys(void):Iterator keys: sharedKeys, // Map#values(void):Iterator values: sharedValues, // Map#entries(void):Iterator entries: mapEntries, // Map#forEach(callback:Function, context:void*):void ==> callback.call(context, key, value, mapObject) === not in specs forEach: sharedForEach, // Map#clear(): clear: sharedClear }); }
map.js
require('../modules/es6.object.to-string'); require('../modules/es6.string.iterator'); require('../modules/web.dom.iterable'); require('../modules/es6.map'); module.exports = require('../modules/_core').Map;
If you console.log Map before you import the core-js map implementation in your webpart file, it will spit out the createCollection function. Once you've imported core-js/es6/map your next console.log will never finish because of an out of stack space exception.
This issue has been noted here as well, though the relation to polyfills only was not noticed:
angular/zone.js#316
BenGWeeks/sp-dev-fx-webparts#1
Steps to Reproduce
Yo @Microsoft/SharePoint a new solution and add either ES6 Polyfill to your code, run a gulp serve and try to use it in Internet Explorer.