如何解决Webpacker 构建错误,“loader”一词之间的空格为“lo ader.js”
我一直收到同样的错误。在过去的 5 次构建中,我没有接触过 Webpacker,并且突然因为一些简单代码中的一个小改动而出错。真的开始让我感到困惑。
我似乎在“错误”行 (4) 中的“错误”中的“加载程序”一词中出现了一个空格。我觉得这就是原因。
这是输出错误:
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-plugin
和 webpack
有帮助:
npm install webpack@latest
npm install html-webpack-plugin@latest
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。