0
votes

I have the following webpack config file:

var webpack = require('webpack');

var config = {
    context: __dirname + '/src', // `__dirname` is root of project and `src` is source
    entry: {
        app: './app.js',
    },
    output: {
        path: __dirname + '/dist', // `dist` is the destination
        filename: '[name].bundle.js',
    },
    devServer: {
        open: true, // to open the local server in browser
        contentBase: __dirname + '/src'
    },
    module: {
        rules: [
            {
                test: /\.js$/, //Check for all js files
                    use: [{
                        loader: 'babel-loader',
                        options: { presets: ['es2015'] }
                }]
            }
        ]
    }
};

module.exports = config;

when I run "webpack-dev-server" I get the following error:

ERROR in (webpack)-dev-server/client?http://localhost:8080 Module build failed: Error: Couldn't find preset "es2015" relative to directory "/usr/local/lib/node_modules/webpack-dev-server/client/index.js?http:/"

1
did you install it as npm install --save babel-preset-es2015 ? - erdysson
npm install --save-dev babel-loader babel-core babel-preset-es2015 - Alessandro
can you try creating a .babelrc file in the project root and put inside { "presets": ["es2015"] } - erdysson
I am following this tutorial: github.com/gokulkrishh/how-to-setup-webpack-2 and it doesn't mention to add a .babelrc file - Alessandro

1 Answers

0
votes

Faced the same problem following a tutorial on Udemy. Adding the .babelrc worked for me.