Reputation: 406
Some find and findIndex method of my Javascript project is not working in IE 11. Here package.json
{
"name": "form_builder_p1_old",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel js -d lib"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/plugin-transform-spread": "^7.2.2",
"@babel/preset-env": "^7.4.5"
},
"dependencies": {
"@babel/polyfill": "^7.4.4",
"@babel/runtime": "^7.4.5",
"core-js": "^3.0.1",
"lodash": "^4.17.11",
"regenerator-runtime": "^0.13.2"
}
}
and .babelrc
{
"presets":[
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": "^3.0.1"
}
]
],
"plugins": ["@babel/plugin-transform-spread"]
}
Babel is working fine in IE. But find methods are not working. i have try polyfil but no success, here is my project dir.
Please help me.
Thanks
Upvotes: 2
Views: 1723
Reputation: 149
I encountered the same situation. Maybe you can use a hand-written polyfill, from the MDN document of Array.prototype.find.
// https://tc39.github.io/ecma262/#sec-array.prototype.find
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function(predicate) {
// 1. Let O be ? ToObject(this value).
if (this == null) {
throw TypeError('"this" is null or not defined');
}
var o = Object(this);
// 2. Let len be ? ToLength(? Get(O, "length")).
var len = o.length >>> 0;
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (typeof predicate !== 'function') {
throw TypeError('predicate must be a function');
}
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
var thisArg = arguments[1];
// 5. Let k be 0.
var k = 0;
// 6. Repeat, while k < len
while (k < len) {
// a. Let Pk be ! ToString(k).
// b. Let kValue be ? Get(O, Pk).
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
// d. If testResult is true, return kValue.
var kValue = o[k];
if (predicate.call(thisArg, kValue, k, o)) {
return kValue;
}
// e. Increase k by 1.
k++;
}
// 7. Return undefined.
return undefined;
},
configurable: true,
writable: true
});
}
Upvotes: 0
Reputation: 31
I solved this problem by adding the following line for core-js@3.
import 'core-js/stable';
import 'regenerator-runtime/runtime';
See @ https://babeljs.io/blog/2019/03/19/7.4.0
Add a partial module manually.
import 'core-js/modules/es.array.find';
Upvotes: 2