alvin lal
alvin lal

Reputation: 129

webpack with babel showing error Module build failed (from ./node_modules/babel-loader/lib/index.js):

I am trying to create a react app using webpack and babel,but when i actually start webpack dev server,using yarn run start,it shows the following error:-

i am using babel-loader version 8.1.0 and @babel/core version 7.10.2

enter image description here

My package.json:-

{
  "name": "reactTemplate",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "webpack-dev-server --mode development --open --hot",
    "build": "webpack --mode production"
  },
  "dependencies": {
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "devDependencies": {
    "babel-loader": "^8.1.0",
    "@babel/core": "^7.10.2",
    "@babel/preset-env": "^7.10.2",
    "@babel/preset-react": "^7.10.1",
    "html-webpack-plugin": "^4.3.0",
    "webpack": "^4.43.0",
    "webpack-cli": "^3.3.11",
    "webpack-dev-server": "^3.11.0"
  }
}

My .babelrc:-

{
  "presets": ["@babel/preset-env", "@babel/preset-react"]
}

My webpack.config.js:-

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: './src/index',
  output: {
    path: path.join(__dirname, './dist'),
    filename: 'index_bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
        },
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html',
    }),
  ],
};

Upvotes: 0

Views: 1735

Answers (1)

Rain.To
Rain.To

Reputation: 512

If you are running a very simple hello world example and extension is js then your settings seem fine. If you are using jsx files as well the add this to the webpack

  test: /\.(js|jsx)$/,

Upvotes: 2

Related Questions