Webpacker 构建错误,space 之间的单词 'loader' 为 'lo ader.js'

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

我不断收到同样的错误。在过去的 5 次构建中,我没有接触过 Webpacker,突然因为一些简单代码的小改动而出错。真的开始让我困惑了。

在错误行 (4) 的“错误”中,我似乎在单词 'loader' 中得到了 space。我觉得是这个原因。

这里是输出错误:

    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 配置:

    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>

刚得到同样的错误,即使一切都被 package-lock.json 文件锁定,并且在 2 天前构建成功。

更新 html-webpack-pluginwebpack 帮助:

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