I am following a tutorial in which the following line works:
['hashchange', 'load'].forEach(ev => console.log(ev));
I write it and I get:
Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')
at Object.eval (eval at hmrApply (runtime-378176c723eb17dd.js:297), <anonymous>:143:12)
at newRequire (index.05cf099e.js:71)
at hmrAcceptRun (runtime-378176c723eb17dd.js:370)
at WebSocket.ws.onmessage (runtime-378176c723eb17dd.js:127)
The project is using Parcel: parcel index.html
.
It also imports core-js/stable
and regenerator-runtime/runtime
.
If I create a variable holding the array and then call forEach()
on that array it works:
const arr = ['hashchange', 'load'];
arr.forEach(ev => console.log(ev));
at Object.eval (eval at hmrApply (runtime-378176c723eb17dd.js:297), :143:12):
function hmrApply(bundle
/*: ParcelRequire */
, asset
/*: HMRAsset */
) {
var modules = bundle.modules;
if (!modules) {
return;
}
if (asset.type === 'css') {
reloadCSS();
} else if (asset.type === 'js') {
var deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
if (deps) {
var fn = new Function('require', 'module', 'exports', asset.output); // line 297
modules[asset.id] = [fn, deps];
} else if (bundle.parent) {
hmrApply(bundle.parent, asset);
}
}
}
at newRequire (index.05cf099e.js:71):
function newRequire(name, jumped) {
// a big function
var module = (cache[name] = new newRequire.Module(name));
modules[name][0].call( // line 71
module.exports,
localRequire,
module,
module.exports,
this
);
}
at hmrAcceptRun (runtime-378176c723eb17dd.js:370):
function hmrAcceptRun(bundle
/*: ParcelRequire */
, id
/*: string */
) {
// a big function
bundle(id); // line 370
cached = bundle.cache[id];
at WebSocket.ws.onmessage (runtime-378176c723eb17dd.js:127)
ws.onmessage = function (event
/*: {data: string, ...} */
) {
// a big function
if (!acceptedAssets[id]) {
hmrAcceptRun(assetsToAccept[i][0], id); // line 127
}
}