0

I've configured webpack@5.10.0 (with webpack-cli@4.2.0) to work with html-webpack-plugin (plus file-loader@6.2.0 and sass-loader@10.1.0):

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const postcssPresetEnv = require('postcss-preset-env');

module.exports = {
  entry: {
    index: './src/index.js',
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: './src/index.html',
    }),
    new MiniCssExtractPlugin({
      filename: '[name].css',
    }),
  ],
  output: {
    publicPath: './',
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
  },
  module: {
    rules: [
      {
        test: /\.s?css$/i,
        use: [
          { loader: MiniCssExtractPlugin.loader },
          'css-loader',
          { 
            loader: 'postcss-loader',
            options: {
              ident: 'postcss',
              plugins: () => [
                postcssPresetEnv(/* pluginOptions */)
              ]
            }
          },
          'sass-loader',
        ],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        loader: 'file-loader',
      },
    ],
  },
};

Up to that point, everything is working fine (style.scss is imported in index.js, the stylesheet itself loads 2 jpgs with background-image: url(...)).

Now, my html template (index.html) references a file (<img src="./file.svg">), that gets copied (by file-loader, with another name). But the reference on the final index.html must reflect this change.

So I installed html-loader@1.3.2:

  [...]
  module: {
    rules: [
      {
        test: /\.html$/i,
        loader: 'html-loader',
      },
  [...]

Now npx webpack build crashes without further instructions:

[webpack-cli] Compilation finished
assets by status 84 KiB [cached] 2 assets
./src/index.js 26 bytes [built] [code generated]
1 ERROR in child compilations
webpack 5.10.0 compiled with 1 error in 867 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Now what? How to get debugging information? What has gone wrong?


$ npm list

a@1.0.0 /home/rslemos/workspace/a/webpack
├── clean-webpack-plugin@3.0.0
├── css-loader@5.0.1
├── file-loader@6.2.0
├── html-loader@1.3.2
├── html-webpack-plugin@4.5.0
├── lodash@4.17.20
├── mini-css-extract-plugin@1.3.2
├── node-sass@5.0.0
├── postcss-loader@3.0.0
├── postcss-preset-env@6.7.0
├── sass-loader@10.1.0
├── sass@1.30.0
├── style-loader@2.0.0
├── webpack-cli@4.2.0
└── webpack@5.10.0
rslemos
  • 2,454
  • 22
  • 32
  • I'm afraid I fell victim of a dependency hell on webpack's, -cli's, plugins', loaders' versions. Is there a place that collects which versions are compatible with each other? – rslemos Dec 07 '20 at 19:37
  • Which package versions did you move to to correct the dependency issue? – Michael Wasser Jan 19 '21 at 01:09

0 Answers0