Error encountered in Webpack configuration while using html-webpack-plugin to generate index.html file

I've been experimenting with webpack to bundle project JS files.

My goal is to generate an index.html file under the output dist folder using webpack. To achieve this, I followed the instructions provided in the webpack documentation and installed "html-web-plugin" via npm as shown below:

npm install --save-dev html-webpack-plugin

This package installation reflected in my package.json file with the following update:

"devDependencies": {
    "html-webpack-plugin": "^4.3.0"
}

I included this plugin in my webpack.config.js file based on the documentation of webpack:

const HtmlWebpackPlugin = require('html-webpack-plugin');

Inside the configuration object:

plugins: [
  new HtmlWebpackPlugin({
      title: 'Output Management'
  })
],

To execute npm scripts, I added the following code snippet in my package.json file:

"scripts": {
  "devNoServer": "webpack --d --watch",
  "dev": "webpack-dev-server",
  "build": "webpack -p",
  "test": "echo \"Error: no test specified\" && exit 1"
},

However, when running either npm run dev or npm run build, I encountered the error message below which seems to be related to the html-web-plugin:

/<PROJECT_PATH>/node_modules/webpack-dev-server/bin/webpack-dev-server.js:373
    throw e;
    ^

TypeError: Cannot read property 'make' of undefined
    at PersistentChildCompilerSingletonPlugin.apply (/<PROJECT_PATH>/node_modules/html-webpack-plugin/lib/cached-child-compiler.js:182:20)
    at new CachedChildCompilation (/<PROJECT_PATH>/node_modules/html-webpack-plugin/lib/cached-child-compiler.js:68:44)
    at HtmlWebpackPlugin.apply (/<PROJECT_PATH>/node_modules/html-webpack-plugin/index.js:92:33)
    at Compiler.apply (/<PROJECT_PATH>/node_modules/tapable/lib/Tapable.js:375:16)
    at webpack (/<PROJECT_PATH>/node_modules/webpack/lib/webpack.js:33:19)
    at startDevServer (/<PROJECT_PATH>/node_modules/webpack-dev-server/bin/webpack-dev-server.js:367:16)
    at /<PROJECT_PATH>/node_modules/webpack-dev-server/bin/webpack-dev-server.js:358:5
    at /<PROJECT_PATH>/node_modules/portfinder/lib/portfinder.js:196:16
    at /<PROJECT_PATH>/node_modules/async/dist/async.js:473:16
    at replenish (/<PROJECT_PATH>/node_modules/async/dist/async.js:1006:25)
npm ERR! code ELIFECYCLE
...
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /<USER_DIR>/.npm/_logs/2020-06-17T14_50_38_388Z-debug.log

Interestingly, when I do not use the "html-webpack-plugin", the npm run dev or npm run build commands work fine and generate the bundle.js file in the dist folder.

I'm struggling to identify what I might be doing wrong while setting up the "html-webpack-plugin". Any advice or solutions would be greatly appreciated.

Answer №1

After extensive searching and reviewing various documentation, I finally found a solution that worked for me. I had originally been using the "html-webpack-plugin": "^4.3.0", but after encountering issues, I decided to switch back to using[email protected]. To my surprise, this resolved the problem I was facing with the make command. It seems like it could potentially be an issue with versions.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing the Symfony Process command `npm install` is successful when using the Command Line Interface (CLI), but encounters

Recently, I encountered a rather peculiar problem that has piqued my curiosity. I am hoping you can shed some light on why this issue is occurring. Please note: I'm aware that this might not be the best practice and is more of an experiment than a re ...

Obtain the value of an element from a React UI Material component (e.g. ListItemText)

Incorporated an onClick() event where a function is invoked to retrieve and display the value of any clicked element within the HTML body in a web component. <div id="root" onclick="handleClick(event)"></div> This snippet o ...

Run a Python script to capture mouse coordinates using Selenium

Greetings, I am currently utilizing selenium webdriver to retrieve the X,Y coordinates of the cursor at a specific moment on the webdriver screen. However, I am facing challenges with the implementation of a method that involves using driver.execute_script ...

Organize table information using rowspan functionality

View of Current Table I am looking to implement a side column in my table using rowspan to group dates within each pay period. The goal is for a supervisor to be able to create a new pay period, which will assign a unique integer in the database and then ...

Having trouble changing my array state in react?

I'm having trouble understanding why my React state isn't updating with the following code: state = { popUpMessages:[] } popUpMessage(id,name) { console.log("id ",id,"name ",name) const addUserObject = { id, name }; const new ...

What is the best way to dynamically set the 'selected' attribute in HTML dropdown options using AngularJS data?

I'm currently in the process of developing an angularJS application. Below is a snippet of my PHP code: <label class="item item-input item-select"> <div class="input-label">Do you possess the right to work in the UK?</div> & ...

Tips for validating user input within a specific range in React?

I need to restrict user input in an input field to a number range defined by minimum and maximum values. I am working on this functionality using React/Next js. <Input value={tripCoverage} onChange={(e) => { const value = e.target.v ...

retrieve information from a div using an AJAX request

I don't have much experience with ajax and javascript, but I need some assistance, so I will do my best to explain clearly! Below is the JavaScript associated with a button: $('#button-confirm').on('click', function() { $.ajax({ ...

Sending JSON data stored in a JavaScript variable through a jQuery POST request

I am currently attempting to retrieve data from a remote location using a JQuery post method. It works perfectly fine when I directly input the data to be posted, but for some reason, it fails when I store the JSON in a JavaScript variable and pass it in. ...

What is the best way to save only the time in MySQL using Sequelize?

How can I properly store the Time HH:MM:SS using sequelize without encountering errors? I've tried using Time as a String and also as a Date Object, but I'm still facing issues. Here is the function I am using: const dateCollection = await booki ...

What steps can be taken to troubleshoot issues with the jquery mask plugin?

I am using the jQuery Mask Plugin available at to apply masks to input fields on my website. Currently, I am trying to implement a mask that starts with +38 (0XX) XXX-XX-XX. However, I am facing an issue where instead of mandating a zero in some places, ...

The present IP address of the client through AJAX and PHP

This code snippet is on my PHP page: // Setting the timezone to Asia/Manila date_default_timezone_set('Asia/Manila'); $date = date('m/d/Y h:i:s a', time()); if (!empty($_SERVER['HTTP_CLIENT_IP'])){ $ip=$_SERVER['HTTP_C ...

Creating a sticky v-stepper-header while scrolling in VuetifyJS

Can anyone help me figure out how to make the <v-stepper-header> component stay sticky when scrolling? I attempted to create custom CSS for this but was unsuccessful. Below is a snippet of code that I tried: <v-stepper v-model="step"&g ...

Angular.js: Applying a style to elements beyond the current scope based on the selected route

I'm looking to dynamically add classes outside of the current scope. Specifically, I need to add classes to the header, main, and footer elements as shown below: <header class="{{pageClass}}"></header> <main class="{{pageClass}}" ng-vi ...

The data received from the frontend is being replicated in the backend, causing duplication issues in a React

Whenever I click the button labeled onClick, it triggers the transmission of data (both time and ID) to the backend. The issue at hand is that the backend seems to be receiving the data twice instead of just once. On inspecting req.body, it becomes eviden ...

What is the reasoning behind having additional parameters right next to require('../models/owners.js')?

import('../utils/handlers.js')(database, Sequelize); The structure of using import(..something)(why?) consecutively is a bit confusing to me. Can you explain it further? ...

Using JQuery to eliminate Javascript code after setting up an event listener, but prior to the listener being activated

Having trouble finding a solution to my question through search. I'm sorry if it has already been asked before. I am attempting to define an event listener and immediately remove the JS code after defining it. The challenge is that I want the removal ...

What is the process for activating focus on an input element within a mat-select component?

How can I activate the cursor on the HTML input element (search field) using a keyboard inside mat-select? It functions properly when using a mouse, but in order to meet WCAG requirements, it needs to be fully functional with keyboard navigation. Click h ...

What is the correct method to include basic authentication headers in a post request for retrieving HTML content?

One of the projects I'm currently working on involves a POST endpoint that is protected by basic auth and returns an HTML form. This particular endpoint is hosted using an express server and secured with passport's basic auth. My goal is to creat ...

Issue: ReactJS - $npm_package_version variable not functioning properly in build versionIn the current

After trying this suggested solution, unfortunately, it did not work for my specific case. The React application I am working on was initialized with CRA version 5.0.1 and currently has a version of 18.2.0. Additionally, the dotenv version being used is 1 ...