parcel: Parcel 2 - IE11 syntax error with ES6 arrow functions in Parcel code
π bug report
IE11 has a syntax error - some ES6 arrow functions are used in Parcel 2 code itself.
π Configuration (.babelrc, package.json, cli command)
I donβt have a .babelrc
, just default browsers list in package.json
:
{
"browserslist": [
"defaults"
]
}
π€ Expected Behavior
IE11 should render the UI, with no JS errors, as all ES6 code should be transpiled.
π― Current Behavior
No JS works in IE11, including polyfills, because Parcel 2 code uses ES6 arrow functions.
This also breaks CSS, because Iβm using a polyfill for :root
CSS Variables.
π» Code Sample
Shows the full contents of the bundled index.js
file, which contains 3 ES6 arrow functions in Parcel 2 code.
NOTE: To mininmise bundle size, and to aid debugging, my source index.js
has no JS functionality whatsoever, just a Sass file import.
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
(function(modules, cache, entry, mainEntry, globalName) {
/* eslint-disable no-undef */
var globalObject =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {};
/* eslint-enable no-undef */
// Save the require from previous bundle to this closure if any
var previousRequire =
typeof globalObject.parcelRequire === 'function' &&
globalObject.parcelRequire;
// Do not use `require` to prevent Webpack from trying to bundle this call
var nodeRequire =
typeof module !== 'undefined' &&
typeof module.require === 'function' &&
module.require.bind(module);
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire =
typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error("Cannot find module '" + name + "'");
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = (cache[name] = new newRequire.Module(name));
modules[name][0].call(
module.exports,
localRequire,
module,
module.exports,
this
);
}
return cache[name].exports;
function localRequire(x) {
return newRequire(localRequire.resolve(x));
}
function resolve(x) {
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function(id, exports) {
modules[id] = [
function(require, module) {
module.exports = exports;
},
{},
];
};
globalObject.parcelRequire = newRequire;
for (var i = 0; i < entry.length; i++) {
newRequire(entry[i]);
}
if (mainEntry) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(mainEntry);
// CommonJS
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = mainExports;
// RequireJS
} else if (typeof define === 'function' && define.amd) {
define(function() {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
})({"4lxY4":[function(require,module,exports) {
var global = arguments[3];
var HMR_HOST = null;
var HMR_PORT = 1234;
var HMR_ENV_HASH = "d751713988987e9331980363e24189ce";
module.bundle.HMR_BUNDLE_ID = "2a79d69e0c3da1a60af25be83b32ed42";
/* global HMR_HOST, HMR_PORT, HMR_ENV_HASH */
var OVERLAY_ID = '__parcel__error__overlay__';
var OldModule = module.bundle.Module;
function Module(moduleName) {
OldModule.call(this, moduleName);
this.hot = {
data: module.bundle.hotData,
_acceptCallbacks: [],
_disposeCallbacks: [],
accept: function (fn) {
this._acceptCallbacks.push(fn || function () {});
},
dispose: function (fn) {
this._disposeCallbacks.push(fn);
}
};
module.bundle.hotData = null;
}
module.bundle.Module = Module;
var checkedAssets, assetsToAccept, acceptedAssets; // eslint-disable-next-line no-redeclare
var parent = module.bundle.parent;
if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== 'undefined') {
var hostname = HMR_HOST || (location.protocol.indexOf('http') === 0 ? location.hostname : 'localhost');
var port = HMR_PORT || location.port;
var protocol = location.protocol === 'https:' ? 'wss' : 'ws';
var ws = new WebSocket(protocol + '://' + hostname + (port ? ':' + port : '') + '/');
ws.onmessage = function (event) {
checkedAssets = {};
assetsToAccept = [];
acceptedAssets = {};
var data = JSON.parse(event.data);
if (data.type === 'update') {
// Remove error overlay if there is one
removeErrorOverlay();
let assets = data.assets.filter(asset => asset.envHash === HMR_ENV_HASH); // Handle HMR Update
var handled = false;
assets.forEach(asset => {
var didAccept = asset.type === 'css' || hmrAcceptCheck(global.parcelRequire, asset.id);
if (didAccept) {
handled = true;
}
});
if (handled) {
console.clear();
assets.forEach(function (asset) {
hmrApply(global.parcelRequire, asset);
});
for (var i = 0; i < assetsToAccept.length; i++) {
var id = assetsToAccept[i][1];
if (!acceptedAssets[id]) {
hmrAcceptRun(assetsToAccept[i][0], id);
}
}
} else {
window.location.reload();
}
}
if (data.type === 'error') {
// Log parcel errors to console
for (let ansiDiagnostic of data.diagnostics.ansi) {
let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
console.error('π¨ [parcel]: ' + ansiDiagnostic.message + '\n' + stack + '\n\n' + ansiDiagnostic.hints.join('\n'));
} // Render the fancy html overlay
removeErrorOverlay();
var overlay = createErrorOverlay(data.diagnostics.html);
document.body.appendChild(overlay);
}
};
ws.onerror = function (e) {
console.error(e.message);
};
ws.onclose = function (e) {
console.warn('[parcel] π¨ Connection to the HMR server was lost');
};
}
function removeErrorOverlay() {
var overlay = document.getElementById(OVERLAY_ID);
if (overlay) {
overlay.remove();
console.log('[parcel] β¨ Error resolved');
}
}
function createErrorOverlay(diagnostics) {
var overlay = document.createElement('div');
overlay.id = OVERLAY_ID;
let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
for (let diagnostic of diagnostics) {
let stack = diagnostic.codeframe ? diagnostic.codeframe : diagnostic.stack;
errorHTML += `
<div>
<div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
π¨ ${diagnostic.message}
</div>
<pre>
${stack}
</pre>
<div>
${diagnostic.hints.map(hint => '<div>' + hint + '</div>').join('')}
</div>
</div>
`;
}
errorHTML += '</div>';
overlay.innerHTML = errorHTML;
return overlay;
}
function getParents(bundle, id) {
var modules = bundle.modules;
if (!modules) {
return [];
}
var parents = [];
var k, d, dep;
for (k in modules) {
for (d in modules[k][1]) {
dep = modules[k][1][d];
if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) {
parents.push([bundle, k]);
}
}
}
if (bundle.parent) {
parents = parents.concat(getParents(bundle.parent, id));
}
return parents;
}
function updateLink(link) {
var newLink = link.cloneNode();
newLink.onload = function () {
if (link.parentNode !== null) {
link.parentNode.removeChild(link);
}
};
newLink.setAttribute('href', link.getAttribute('href').split('?')[0] + '?' + Date.now());
link.parentNode.insertBefore(newLink, link.nextSibling);
}
var cssTimeout = null;
function reloadCSS() {
if (cssTimeout) {
return;
}
cssTimeout = setTimeout(function () {
var links = document.querySelectorAll('link[rel="stylesheet"]');
for (var i = 0; i < links.length; i++) {
var href = links[i].getAttribute('href');
var absolute = /^https?:\/\//i.test(href) && href.indexOf(window.location.origin) !== 0;
if (!absolute) {
updateLink(links[i]);
}
}
cssTimeout = null;
}, 50);
}
function hmrApply(bundle, asset) {
var modules = bundle.modules;
if (!modules) {
return;
}
if (modules[asset.id] || !bundle.parent) {
if (asset.type === 'css') {
reloadCSS();
} else {
var fn = new Function('require', 'module', 'exports', asset.output);
modules[asset.id] = [fn, asset.depsByBundle[bundle.HMR_BUNDLE_ID]];
}
} else if (bundle.parent) {
hmrApply(bundle.parent, asset);
}
}
function hmrAcceptCheck(bundle, id) {
var modules = bundle.modules;
if (!modules) {
return;
}
if (!modules[id] && bundle.parent) {
return hmrAcceptCheck(bundle.parent, id);
}
if (checkedAssets[id]) {
return;
}
checkedAssets[id] = true;
var cached = bundle.cache[id];
assetsToAccept.push([bundle, id]);
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
return true;
}
return getParents(global.parcelRequire, id).some(function (v) {
return hmrAcceptCheck(v[0], v[1]);
});
}
function hmrAcceptRun(bundle, id) {
var cached = bundle.cache[id];
bundle.hotData = {};
if (cached && cached.hot) {
cached.hot.data = bundle.hotData;
}
if (cached && cached.hot && cached.hot._disposeCallbacks.length) {
cached.hot._disposeCallbacks.forEach(function (cb) {
cb(bundle.hotData);
});
}
delete bundle.cache[id];
bundle(id);
cached = bundle.cache[id];
if (cached && cached.hot && cached.hot._acceptCallbacks.length) {
cached.hot._acceptCallbacks.forEach(function (cb) {
var assetsToAlsoAccept = cb(function () {
return getParents(global.parcelRequire, id);
});
if (assetsToAlsoAccept && assetsToAccept.length) {
assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
}
});
}
acceptedAssets[id] = true;
}
},{}],"PvjrZ":[function(require,module,exports) {
"use strict";
require("../scss/index-test.scss");
},{"../scss/index-test.scss":"2DJOm"}],"2DJOm":[function() {},{}]},{},["4lxY4","PvjrZ"], "PvjrZ", null)
//# sourceMappingURL=index.js.map
π Your Environment
Software | Version(s) |
---|---|
Parcel | 2.0.0-nightly.352 |
Node | v12.14.1 |
npm/Yarn | 6.13.4 |
Operating System | Windows10 |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (8 by maintainers)
(
node_modules
arenβt transpiled with browserslist config) And not that you have to delete the cache every time, I think there is just a missing invalidation when modifying the browserslist inpackage.json