title: Webpack 5: assets folder is generated only after the second npm run dev command
body: <p>I'm just starting to use Webpack and now I'm trying to set up my project using Webpack 5 and its new feature: asset modules for fonts(tf|woff|woff2|eot|otf) and images(png|jpg|gif|svg). The project  builds sucessfully: I get dist/main.css, dist/main.js, dist/index.html. All images and fonts files are emitted within the output dist directory with [hash][ext][query] filename.</p>
  <p>My project tree is :</p>
  <pre><code>webpack.config.js
  dist
  src
  --css
  --fonts
  --img
  --index.html
  --index.js
  </code></pre>
  <p>My webpack config:</p>
  <pre><code>const path = require('path');
  
  const HTMLWebpackPlugin = require('html-webpack-plugin');
  const {CleanWebpackPlugin} = require('clean-webpack-plugin');
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  const CssMinimizerWebpackPlugin = require('css-minimizer-webpack-plugin'); 
  const TerserWebpackPlugin = require('terser-webpack-plugin');
  
  const NODE_ENV = process.env.NODE_ENV;
  const IS_DEV = NODE_ENV === 'development';
  const IS_PROD = !IS_DEV;
  
  module.exports = {
  mode: NODE_ENV ? NODE_ENV : 'development',
  entry: path.resolve(__dirname, 'src/index.js'),
  output : {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist'),
      publicPath: './',
      // assetModuleFilename: 'assets/[hash][ext][query]',
  },
  
  module: {
      rules: [
  
          {
          test: /\.html$/,
          use: 'html-loader'
          },
  
          {
              test: /\.css$/,
              use: [
                  {
                  loader: MiniCssExtractPlugin.loader, //instead of style-loader
                  options: {
                      publicPath: './'
                      },
                  },
                  'css-loader'
                  ],
          },
  
          {
              test: /\.(png|jpg|gif|svg)$/,
              type: 'asset/resource',
              // generator: {
              //  filename: 'images/[hash][ext][query]'
              // }
          },
  
          {
              test: /\.(ttf|woff|woff2|eot|otf)$/,
              type: 'asset/resource',
          },
      ],
  },
  
  plugins:
  [
      new CleanWebpackPlugin({
          cleanStaleWebpackAssets: false
      }),
  
      new HTMLWebpackPlugin({
          template: path.resolve(__dirname, 'src/index.html'),
          minify: {
              collapseWhitespace: IS_PROD,
          }
      }),
  
      new MiniCssExtractPlugin(),
  ],
  
  optimization: {
      minimizer: [
          new CssMinimizerWebpackPlugin(),
          new TerserWebpackPlugin(),
      ],
  },
  
  devServer: {
      port: 3000,
      hot: true,
  }
  </code></pre>
  <p>}</p>
  <p><strong>Problem #1</strong>: When I set assetModuleFilename: 'assets/[hash][ext][query]' to the output in my webpack config</p>
  <pre><code>module.exports = {
  mode: NODE_ENV ? NODE_ENV : 'development',
  entry: path.resolve(__dirname, 'src/index.js'),
  output : {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist'),
      publicPath: './',
      assetModuleFilename: 'assets/[hash][ext][query]',
  },
  </code></pre>
  <p>and run build (npm run dev) FIRST time I get error.</p>
  <pre><code> Error: EPERM: operation not permitted, lstat 'E:\WEB\MiTravel\MiTravel\dist\assets\0a04460c0a144cf3f0a9.svg'
  at Object.lstatSync (fs.js:1077:3)
  at Function.rimrafSync [as sync] (E:\WEB\MiTravel\MiTravel\node_modules\rimraf\rimraf.js:299:24)
  at E:\WEB\MiTravel\MiTravel\node_modules\del\index.js:65:11
  at Array.map (&lt;anonymous&gt;)
  at module.exports.sync (E:\WEB\MiTravel\MiTravel\node_modules\del\index.js:57:40)
  at CleanWebpackPlugin.removeFiles (E:\WEB\MiTravel\MiTravel\node_modules\clean-webpack-plugin\dist\clean-webpack-plugin.js:198:37)
  </code></pre>
  <p>At this moment there are sucessfully built main.js, index.html, main.css and NO dist/assets dir in the output dist directory. Then I just repeat (SECOND time) npm run dev command and get dist/assets dir with all assets files and main.js, index.html, main.css in the output dist directory. And all fonts and images are ok.</p>
  <p>I googled the error, tried to change different parametres but I still can't fix this bug.</p>
  <p>Thank you in advance for help and advice.</p>