Search code examples
reactjsmernwebpacker

Webpacker build error, space between the word 'loader' as 'lo ader.js'


I keep getting the same error. I have not touched Webpacker for the past 5 builds, and suddenly getting errors for a small change in some simple code. Really starting to baffle me.

I seem to be getting a space in the word 'loader', on the 'ERROR in Error line (4). I feel that is the cause.

Here is the output error:

    WARNING in webpack performance recommendations: 
    You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
    For more info visit https://webpack.js.org/guides/code-splitting/
    
    ERROR in Error: The loader "/usr/src/app/client/node_modules/html-webpack-plugin/lib/lo  ader.js!/usr/src/app/client/public/index.html" didn't return html.
      
      - index.js:330 HtmlWebpackPlugin.evaluateCompilationResult
        [client]/[html-webpack-plugin]/index.js:330:24
      
      - index.js:237 
        [client]/[html-webpack-plugin]/index.js:237:22
      
      - runMicrotasks
      
      - task_queues.js:93 processTicksAndRejections
        internal/process/task_queues.js:93:5
      
      - async Promise.all
      
      - async Promise.all
    
    webpack 5.22.0 compiled with 1 error and 3 warnings in 38437 ms
    

Webpack Configuration:

    const path = require("path");
    const webpack = require('webpack');
    const dotenv = require('dotenv');
    var HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = function(_env, argv) {
      const isProduction = argv.mode === "production";
      const isDevelopment = !isProduction;
    
      return {
        devtool: isDevelopment && "cheap-module-source-map",
        entry: "./src/index.js",
        
        module: {
          rules: [
              {
                  test: /\.jsx?$/,
                  loader: 'babel-loader'
              },
              {
                test: /\.css$/,
                use: ["style-loader", "css-loader"]
              },
              {
                test: /\.svg$/,
                use: [
                  {
                    loader: 'svg-url-loader',
                    options: {
                      limit: 10000,
                    },
                  },
                ],
              },
              {
                test: /\.(woff(2)?|png|jpe?g|gif)$/i,
                use: [
                  {
                    loader: 'file-loader',
                  },
                ],
              },
              {
                test: /\.html$/,
                use: [
                  {
                    loader: "html-loader"
                  }
                ]
              },
          ]
      },
      plugins: [new HtmlWebpackPlugin({
     template: "./public/index.html",
     filename: "./index.html"
    }),
    new webpack.DefinePlugin({
     'process.env': JSON.stringify(dotenv.config().parsed) // it will automatically pick up key values from .env file
     })], 
     };
    };

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-TBNHVKT');</script>
  <!-- End Google Tag Manager -->
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <script src="https://js.stripe.com/v3/"></script>

    
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>CarXpert</title>
  </head>
  <body>
    <!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-TBNHVKT"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>


Solution

  • Just got the same error, even though everything was locked down with package-lock.json files, and was building successfully 2 days ago.

    Updating html-webpack-plugin and webpack helped:

    npm install webpack@latest
    npm install html-webpack-plugin@latest