M
M
Michael R.2020-12-09 12:32:03
JavaScript
Michael R., 2020-12-09 12:32:03

Webpack throws an error when processing an html file, how to fix it?

Greetings!

When building via Webpack, it gives errors. The essence of the error: when building home.html, webpack for some reason tries to find js code inside html tags.

Mistake:

ERROR in ./src/home.html (./node_modules/html-webpack-plugin/lib/loader.js!./src/home.html)
Module build failed (from ./node_modules/html-loader/index.js):
Error: Line 151: Unexpected identifier
  at ErrorHandler.constructError (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:3396:22)
  at ErrorHandler.createError (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:3414:27)
  at JSXParser.Parser.unexpectedTokenError (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:542:39)
  at JSXParser.Parser.throwUnexpectedToken (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:552:21)
  at JSXParser.Parser.consumeSemicolon (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:845:23)
  at JSXParser.Parser.parseExpressionStatement (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:2080:15)
  at JSXParser.Parser.parseStatement (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:2495:35)
  at JSXParser.Parser.parseStatementListItem (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:1823:31)
  at JSXParser.Parser.parseProgram (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:3061:29)
  at Object.parse (C:\1\node_modules\recast\node_modules\esprima\dist\esprima.js:117:24)


home.html:

151 lines:
<code class="jscript plain">logs.error(`Info of error`, { moduleName:

When checking, I removed slash quotes - the error on this line disappeared, but a similar error appeared on line 168.

Line 168:
<code class="jscript plain">node.classList.add(...node.getAttribute(`data-${

Similarly, removed the slash - the error remained, removed the open curly brace - the error went down to the lines below.

Part from webpack.config.js:
{
  test: /\.js$/,
  exclude: /node_modules/,
  use: {
    loader: "babel-loader",
  },
},

{
  test: /\.html$/,
  exclude: /node_modules/,
  use: {
    loader: "html-loader",
    options: {
      attrs: [
        "img:src",
        "link:href",
        ":data-src",
      ],
      interpolate: true,
    },
  },
},


It turns out that the collector clings to syntax errors in js code, but this is text in html tags ... How to treat?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question