Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel does not accept options

webpack.config.js:

module.exports = {
    entry: __dirname + '/src/app.js',
    output: {
        path: __dirname + '/dist',
        filename: 'test.js'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env', {
                            targets: {
                                chrome: 52
                            }
                        }]
                    }
                }
            }
        ]
    }
};

Looks simple, yet it throws error

Module build failed: ReferenceError: [BABEL] /src/app.js: Unknown option: foreign.targets. Check out http://babeljs.io/docs/usage/options/ for more information about options.

that doesn't make any sense. Error is triggered by options for "env" preset. Any ideas why babel preset suddenly doesn't accept options?

like image 863
Arty Avatar asked Feb 13 '26 23:02

Arty


1 Answers

Figured it out. Preset with options should be in nested array, so correct options list should be like this:

                options: {
                    presets: [
                        ['env', {
                            targets: {
                                chrome: 52
                            }
                        }]
                    ]
                }
like image 200
Arty Avatar answered Feb 21 '26 00:02

Arty