`.find` not being polyfilled
Do you want to request a feature or report a bug?
What is the current behaviour?
Currently, the bundles created from the preact build command are not polyfilling the Array.find method. I can't not find it in the bundle or the polyfill created.
This is surprising, as the default browserslists config is ['> 0.25%', 'IE >= 9'], and I know atleast ie 11 doesn't support .find. Our app is crashing for users who use this IE or <.
Using 2.2.1
If the current behaviour is a bug, please provide the steps to reproduce.
preact create default foo
in your editor, open created project, nav to src > index.js and add the following
import './style';
import App from './components/app';
[].find(() => {})//this line
export default App;
then run npm run build. Search the bundle.js and the polyfills.js. You won't find the polyfill in either.
What is the expected behaviour? It should include a polyfill, probably in the polyfills file. If this is a feature request, what is motivation or use case for changing the behaviour?
Please mention other relevant information.
Please paste the results of preact info here.
@MarkGeeRomano Automatic polyfill injection would be a nice feature, but there are no current solutions for doing this that work well. Preact doesn't polyfill runtime APIs because doing so universally triggers over-polyfilling.
For example, here's the original source:
[].find(() => true);
Here's the default webpack output without preset-env enabled:
✅ Compilation Results
🌏 Version: 4.39.3
⚒️ Built: Tue Feb 11 2020 13:13:35 GMT-0500 (Eastern Standard Time)
⏱ Compile Time: 317ms
📂 Output Directory: /Users/jasonjmiller/Projects/temp7/dist
#️⃣ Hash: 36337ce43af349dd7d3d
┌────────────┬───────────────────────────────┐
│ Entrypoint │ Bundle │
├────────────┼───────────────────────────────┤
│ │ Bundle Name │ main.js │
│ │ Compared For Emit │ │
│ │ Bundle size │ 0.96 kb │
│ │ │
│ │ Modules: │
│ │ ./t.js [size: 87 bytes] │
└────────────┴───────────────────────────────┘
With automatic polyfilling (via preset-env) enabled, here's what Webpack outputs:
✅ Compilation Results
🌏 Version: 4.39.3
⚒️ Built: Tue Feb 11 2020 13:12:53 GMT-0500 (Eastern Standard Time)
⏱ Compile Time: 497ms
📂 Output Directory: /Users/jasonjmiller/Projects/temp7/dist
#️⃣ Hash: d4e629fafcf674d6f730
┌────────────┬────────────────────────────────────────────────────────────────────────────────┐
│ Entrypoint │ Bundle │
├────────────┼────────────────────────────────────────────────────────────────────────────────┤
│ │ Bundle Name │ main.js │
│ │ Compared For Emit │ │
│ │ Bundle size │ 6.56 kb │
│ │ │
│ │ Modules: │
│ │ ./node_modules/core-js/modules/_global.js [size: 369 bytes] │
│ │ ./node_modules/core-js/modules/_is-object.js [size: 110 bytes] │
│ │ ./node_modules/core-js/modules/_core.js [size: 123 bytes] │
│ │ ./node_modules/core-js/modules/_hide.js [size: 286 bytes] │
│ │ ./node_modules/core-js/modules/_descriptors.js [size: 184 bytes] │
│ │ ./node_modules/core-js/modules/_fails.js [size: 104 bytes] │
│ │ ./node_modules/core-js/modules/_uid.js [size: 162 bytes] │
│ │ ./node_modules/core-js/modules/_shared.js [size: 428 bytes] │
│ │ ./node_modules/core-js/modules/_ctx.js [size: 520 bytes] │
│ │ ./node_modules/core-js/modules/_cof.js [size: 106 bytes] │
│ │ ./node_modules/core-js/modules/_wks.js [size: 358 bytes] │
│ │ ./t.js [size: 85 bytes] │
│ │ ./node_modules/core-js/modules/es6.array.find.js [size: 527 bytes] │
│ │ ./node_modules/core-js/modules/_export.js [size: 1601 bytes] │
│ │ ./node_modules/core-js/modules/_object-dp.js [size: 600 bytes] │
│ │ ./node_modules/core-js/modules/_an-object.js [size: 154 bytes] │
│ │ ./node_modules/core-js/modules/_ie8-dom-define.js [size: 199 bytes] │
│ │ ./node_modules/core-js/modules/_dom-create.js [size: 289 bytes] │
│ │ ./node_modules/core-js/modules/_to-primitive.js [size: 655 bytes] │
│ │ ./node_modules/core-js/modules/_property-desc.js [size: 173 bytes] │
│ │ ./node_modules/core-js/modules/_redefine.js [size: 1050 bytes] │
│ │ ./node_modules/core-js/modules/_has.js [size: 120 bytes] │
│ │ ./node_modules/core-js/modules/_function-to-string.js [size: 87 bytes] │
│ │ ./node_modules/core-js/modules/_library.js [size: 24 bytes] │
│ │ ./node_modules/core-js/modules/_a-function.js [size: 125 bytes] │
│ │ ./node_modules/core-js/modules/_array-methods.js [size: 1494 bytes] │
│ │ ./node_modules/core-js/modules/_iobject.js [size: 289 bytes] │
│ │ ./node_modules/core-js/modules/_to-object.js [size: 132 bytes] │
│ │ ./node_modules/core-js/modules/_defined.js [size: 162 bytes] │
│ │ ./node_modules/core-js/modules/_to-length.js [size: 215 bytes] │
│ │ ./node_modules/core-js/modules/_to-integer.js [size: 161 bytes] │
│ │ ./node_modules/core-js/modules/_array-species-create.js [size: 223 bytes] │
│ │ ./node_modules/core-js/modules/_array-species-constructor.js [size: 475 bytes] │
│ │ ./node_modules/core-js/modules/_is-array.js [size: 147 bytes] │
│ │ ./node_modules/core-js/modules/_add-to-unscopables.js [size: 297 bytes] │
└────────────┴────────────────────────────────────────────────────────────────────────────────┘
That's quite a difference, and this is one of the least-bad examples.
comes up literally the next day of the nomodule polyfills discussion.
@developit do you think our approach of polyfills between ie11 and type=module would solve this?