Reputation: 2361
I'm getting this error on IE 11:
Here are my webpack and babel configuations:
webpack configuration
const path = require('path');
const webpack = require('webpack');
const { VueLoaderPlugin } = require('vue-loader');
const StylishWebpackPlugin = require('webpack-stylish');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const withLogRocket = process.argv.includes('--with-logrocket');
if (withLogRocket) {
/* eslint-disable no-console */
console.info('-> Building with LogRocket enabled.');
/* eslint-enable */
}
// Base webpack configuration for all environments.
module.exports = {
context: path.dirname(__dirname),
entry: {
app: './src/main.js',
},
target: 'web',
output: {
filename: '[name].[contenthash].js',
hashDigestLength: 8,
},
resolve: {
extensions: ['.ts', '.js', '.vue'],
alias: {
'@': path.resolve(__dirname, '../src'),
},
},
module: {
rules: [
{
test: /\.js/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader',
],
},
],
},
stats: 'errors-only',
plugins: [
new VueLoaderPlugin(),
new ForkTsCheckerWebpackPlugin({
tslint: true,
reportFiles: ['src/**/*.ts'],
}),
new StylishWebpackPlugin(),
new webpack.DefinePlugin({
USE_LOGROCKET: withLogRocket,
}),
],
};
babelrc file
{
"presets": ["env"],
"plugins": [
"transform-es2015-destructuring",
"transform-object-rest-spread"
]
}
I'm not really sure if this is due to the ...sources
spread or among others. I'm pretty sure I have the babel-transform-object-rest-spread
package but I still don't get why I have this error, I also used babel-preset-env
. As you can see on the configuration I am running a pure JS (VueJS, typescript) app. I've read numerous posts about using polyfill and among others but it didn't help me make our app run on IE11.
Upvotes: 0
Views: 1048
Reputation: 56753
You're using env
preset but never defining what environment Babel is supposed to generate code for (so I assume IE 11 is not supported in that case).
Without any configuration options, babel-preset-env behaves exactly the same as babel-preset-latest (or babel-preset-es2015, babel-preset-es2016, and babel-preset-es2017 together).
So just add the options object having the targets
property set to something the like of
"browsers": [ "last 1 version", "ie >= 11" ]
like this:
{
"presets": ["env", {
"targets": {
"browsers": [ "last 1 version", "ie >= 11" ]
}
}],
"plugins": [
"transform-es2015-destructuring",
"transform-object-rest-spread"
]
}
I also highly recommend you switch to Babel 7 asap.
Upvotes: 2