Webpack chunks are not found

Viewed 3672

I'm trying to setup webpack in my react.js application based on this starter kit

When I start development server, application is build successfully and I can see a list of chunks generated, but then application doesn't load and I got an error in console indicating that chunks were not found.

My webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const Dotenv = require('dotenv-webpack');

const SRC_DIR = path.join(__dirname, '/src');
const PUB_DIR = path.join(__dirname, '/public');
const DIST_DIR = path.join(__dirname, '/dist');

module.exports = {
  entry: { main: `${SRC_DIR}/index.js` },
  output: {
    path: DIST_DIR,
    chunkFilename: '[chunkhash].chunk.js',

  },
  resolve: {
    alias: {
      src: path.resolve(__dirname, 'src/')
    }
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: ['babel-loader', 'source-map-loader'],

      },
      {
        test: /\.(png|jpg)$/,
        use: {
          loader: 'url-loader',
        },
      },
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          MiniCssExtractPlugin.loader,
          'css-loader',
          'sass-loader',
        ],
      },
      {
        test: /\.css$/,

        use: [
          { loader: 'style-loader' },
          {
            loader: 'css-loader',
            options: {
              modules: true
            },
          },
          { loader: 'sass-loader' }
        ]
      }
    ],
  },
  optimization: {
    splitChunks: {
      cacheGroups: {
        css: {
          test: /\.(css|sass|scss)$/,
          name: 'commons',
          chunks: 'all',
          minChunks: 2,
          enforce: true,
        },
      },
    },
  },
  plugins: [
    new CleanWebpackPlugin({
      cleanAfterEveryBuildPatterns: ['dist'],
    }),
    new MiniCssExtractPlugin({
      filename: 'style.[contenthash].css',
    }),
    new HtmlWebpackPlugin({
      inject: true,
      title: 'React-Redux-Webpack-Starter-Kit',
      template: `${PUB_DIR}/index.html`,
      filename: 'index.html',
      favicon: `${PUB_DIR}/favicon.ico`,
      meta: {
        viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
      },
    }),
    new WebpackMd5Hash(),
    new Dotenv(),
  ],
  devServer: {
    port: 3003,
    historyApiFallback: true,
  },

};

My packate.json

    {
  "name": "FillRX",
  "author": "Zoran Jeremic",
  "email": "zoran.jeremic@gmail.com",
  "licence": "UNLICENSED",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "lint": "eslint ./src",
    "start": "webpack-dev-server --open --mode development --watch",
    "prod": "webpack --mode production",
    "build": "cross-env NODE_ENV=production && npm run prod",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "ie 11",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "ie 11",
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "dependencies": {
    "@date-io/core": "^2.5.0",
    "@date-io/moment": "^1.3.13",
    "@fullcalendar/core": "^4.4.0",
    "@fullcalendar/daygrid": "^4.4.0",
    "@fullcalendar/interaction": "^4.4.0",
    "@fullcalendar/list": "^4.4.0",
    "@fullcalendar/react": "^4.4.0",
    "@fullcalendar/timegrid": "^4.4.0",
    "@fullcalendar/timeline": "^4.4.0",
    "@material-ui/core": "^4.9.9",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.48",
    "@material-ui/pickers": "^3.2.10",
    "@material-ui/styles": "^4.9.6",
    "@mdx-js/react": "^1.5.8",
    "@react-pdf/renderer": "^1.6.8",
    "@redux-saga/core": "^1.1.3",
    "apexcharts": "^3.18.0",
    "axios": "^0.19.2",
    "axios-mock-adapter": "^1.17.0",
    "babel-loader": "^8.1.0",
    "change-case": "^4.1.1",
    "chart.js": "^2.9.3",
    "clsx": "^1.1.0",
    "css-loader": "^4.2.1",
    "dotenv-webpack": "^2.0.0",
    "draft-js": "^0.11.5",
    "formik": "^2.1.4",
    "history": "^4.10.1",
    "immer": "^6.0.3",
    "immutable": "^4.0.0-rc.12",
    "js-cookie": "^2.2.1",
    "jsonwebtoken": "^8.5.1",
    "jss": "^10.1.1",
    "jss-rtl": "^0.3.0",
    "jwt-decode": "^2.2.0",
    "lodash": "^4.17.19",
    "moment": "^2.24.0",
    "nan": "^2.14.1",
    "node-sass": "^4.14.1",
    "notistack": "^0.9.9",
    "nprogress": "^0.2.0",
    "prismjs": "^1.20.0",
    "prop-types": "^15.7.2",
    "react": "^16.13.1",
    "react-apexcharts": "^1.3.7",
    "react-app-polyfill": "^1.0.6",
    "react-beautiful-dnd": "^13.0.0",
    "react-big-calendar": "^0.24.1",
    "react-chartjs-2": "^2.9.0",
    "react-dom": "^16.13.1",
    "react-draft-wysiwyg": "^1.14.4",
    "react-dropzone": "^10.2.2",
    "react-feather": "^2.0.3",
    "react-helmet": "^5.2.1",
    "react-markdown": "^4.3.1",
    "react-modal-image": "^2.5.0",
    "react-perfect-scrollbar": "^1.5.8",
    "react-quill": "^1.3.5",
    "react-redux": "^7.2.0",
    "react-router": "^5.1.2",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.4.1",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "redux-form": "^8.3.2",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-saga": "^1.1.3",
    "redux-thunk": "^2.3.0",
    "sass-loader": "^9.0.3",
    "socket.io-client": "^2.3.0",
    "source-map-loader": "^1.0.1",
    "uuid": "^7.0.3",
    "webpack-dev-server": "^3.11.0",
    "webpack-md5-hash": "^0.0.6",
    "yup": "^0.28.3"
  },
  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "dotenv": "^8.2.0",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-config-prettier": "^6.10.1",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-mdx": "^1.6.8",
    "eslint-plugin-prettier": "^3.1.2",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^2.5.1",
    "html-webpack-plugin": "^4.3.0",
    "mdx-loader": "^3.0.2",
    "mini-css-extract-plugin": "^0.9.0",
    "prettier": "^1.19.1",
    "typescript": "^3.8.3",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  }
}

This is the error I'm getting in console:

enter image description here

All these chunks that are not found are generated during the application build, but I guess my configuration can't find it:

enter image description here

I didn't use webpack earlier so I'm not sure how to investigate this problem since error doesn't indicate what could be the problem, and google search gave me results indicating network problem which I don't think is the case here.

I would appreciate any help and suggestion.

1 Answers
Related