I use webpack to bundle my codes for my clients. According to my question here Is it possible to break away from await Promise.all when any promise has fulfilled (Chrome 80) I want to use Promise.any()
but Promise.any
is only available for Chrome85+ and my clients need me to support Chrome 80+. Naturally I had thought with babel I can polyfill Promise.any()
, e.g. corejs provides Promise.any. But I don't know what I did wrong, now with Babel 7 polyfill I can't even make Promise.any work for Chrome85+!
Following is what I have done,
First, my webpack.config.js
module.exports = {
entry: {
index: './src/index.js'
ui:'./src/ui/index.js'
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
libraryTarget: 'umd',
libraryExport: 'default',
umdNamedDefine: true,
library: '[name]'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
...
}
I initially used Babel 6. With Babel 6 I can verify the code (using Promise.any) bundled by webpack works for Chrome 85+ (probably it didn't polyfill Promise.any at all).
I then upgrade Babel 6 to Babel 7, using npx babel-upgrade --write
and with some twists (e.g. "useBuiltIns": 'usage'
). webpack can bundle my code then, but to my surprise the bundled code with Promise.any()
can't even work on Chrome85+. I got the error message "Uncaught (in promise) rejected"
The following is my babelrc
{
"env": {
"production": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"browsers": [
"last 4 Chrome versions",
"last 3 Firefox versions",
]
},
"modules": "commonjs",
"debug": true,
"useBuiltIns": 'usage'
}
]
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 2,
"regenerator": true
}
]
]
}
}
}
What did I do wrong ?