Webpack Reactjs

Asked

Viewed 66 times

1

I am facing problems with my webpack, I get in the terminal this following error:

you may need an appropriate Loader to Handle this file type

webpack.config.js:

var path = require('path');
var webpack = require('webpack');

var DIST_DIR = path.resolve(__dirname, 'src/client/public');
var SRC_DIR = path.resolve(__dirname, 'src');

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js'
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ]
  },
};

package json.:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.17.0",
    "font-awesome": "^4.7.0",
    "react": "^16.0.0",
    "react-bootstrap": "^0.31.5",
    "react-dom": "^16.0.0",
    "react-if": "^2.2.1",
    "react-scripts": "1.0.16",
    "react-simple-chatbot": "^0.2.9",
    "recharts": "^1.0.0-beta.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "webpack": "webpack",
    "babel": "babel",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "webpack": "^3.8.1",
    "webpack-dev-server": "^2.9.4"
  }
}

1 answer

0


Hi, for webpack version 2 and 3, module.loaders has changed to the following format:

module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['react', 'es2015']
          },
        }
      }
    ]
  },
// ...

Note that it is now module.Rules

Browser other questions tagged

You are not signed in. Login or sign up in order to post.