Alex Bollbach
Alex Bollbach

Reputation: 4580

getting error with Webpack - couldn't find present "es2015"

ERROR in (webpack)/node_modules/process/browser.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/usr/local/lib/node_modules/webpack/node_modules/process"

this is my webpack config file:

var path = require('path');

module.exports = {

  entry: [
  './src/App.js',
  ],
  output: { 
    path: path.resolve(__dirname, 'dist'), 
    filename: 'bundle.js'
  },
  module: {
    loaders: [
    {
      test: /\.js$/,
      exclude: ['node_modules'],
      loader: 'babel-loader',
      query: {
        presets: ['es2015', 'react']
      }
    }
    ]
  }
}

This is my package.json file:

{
  "name": "ab-site-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router-dom": "^4.1.2"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "html-loader": "^0.5.1",
    "webpack": "^3.5.4"
  }
}

I do not know what this error means. I have tried getting webpack to work for days now. Each error I get is not helpful and trying to solve it results in creating more errors. I would appreciate any help. I have a .babelrc file with the two presets es2015, and react. I've seen people on the internet telling me to delete it.. to keep it. Maybe my npm is out of date? maybe my webpack is out of date? Nothing I do works and everything I do only makes other errors crop up.

Upvotes: 1

Views: 106

Answers (1)

Sebastian
Sebastian

Reputation: 1305

There are two main ways to configure babel presets: via babel-loader options

  options: {
          presets: ['es2015', 'react']
           }

or via .babelrc. Some prefer one way of doing things, some prefer the other. I use .babelrc.

This config works for me:

In webpack.config.js

{
        test: /\.(js|jsx)$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
        }
      }

in .babelrc

{
  "presets": ["es2015", "react"]
}

Upvotes: 1

Related Questions