
Description
Bug report
I was following the webpack documentation guide.
After installing webpack-dev-server, It's supposed to refresh in place.
However, that is not happening. I got the following error:
Uncaught TypeError: Cannot set properties of undefined (setting './src/index.js')
at self.webpackHotUpdatewebkack_guide (jsonp chunk loading:44:1)
at index.17c225e1ecf28bdb9b74.hot-update.js:2:38
HMR] Update failed: ChunkLoadError: Loading hot update chunk index failed.
(missing: http://localhost:8080/index.17c225e1ecf28bdb9b74.hot-update.js)
I do not understand what could be wrong. It only works after I refresh the page.
Interestingly, I could change any other file than index.js and it refreshes correctly.
The problem appears when I change anything inside index.js
Any suggestion?
Other relevant information:
node v14.16.1
// package.json
{
"name": "webkack-guide",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"watch": "webpack --watch",
"build": "webpack",
"start": "webpack serve --open"
},
"keywords": [],
"author": "",
"license": "ISC",
"private": true,
"devDependencies": {
"html-webpack-plugin": "^5.5.0",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4"
},
"dependencies": {
"lodash": "^4.17.21"
}
}
// index.js
import _ from "lodash";
import printMe from "./print";
function component() {
const element = document.createElement("div");
const btn = document.createElement("button");
element.innerHTML = _.join(["hello", "webpack"], " ");
btn.innerHTML = "click me and check the console";
btn.onclick = printMe;
element.appendChild(btn);
return element;
}
document.body.appendChild(component());
// print.js
export default function printMe() {
console.log("I get called from print.js 5");
}
// webpack.config
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "development",
entry: {
index: "./src/index.js",
print: "./src/print.js",
},
devServer: {
static: "./dist",
},
devtool: "inline-source-map",
plugins: [new HtmlWebpackPlugin({ title: "Output Management" })],
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
clean: true,
},
};
Activity
vankop commentedon Mar 7, 2022
please create reproducible repo. from your description unclear what is a problem, maybe you just need to remove
devServer
option from configavishek143 commentedon Mar 26, 2022
This is a valid documentation issue and most likely belongs to the Documentation repository.
In the Development Guide under Using Watch Mode section the content says:
The follow-on section about webpack-dev-server is expected to provide guidance about creating a setup that would reload new code as it is written and refresh the browser to show the changes. But the code example doesnot do so. The problem is in the
webpack.config.js
code example. ThedevServer
configuration as mentioned will not refresh the browser. To actually refresh the page the minimal configuration that needs to be added todevServer
iswatchFiles: ['src/**/*.*'],
docs(guides): auto reload fixed in Development
alexander-akait commentedon Mar 28, 2022
What do you mean -
refresh
?watchFiles
only for reload when you change externals files (i.e. not used in bundle, for example.php
/.py
/etc)avishek143 commentedon Mar 28, 2022
refresh the browser means reload the browser with the new changed code.
I don't think that is the case. If it is so the documentation must state the same. And there is no code anywhere which will prevent us from mentioning a file that is bundled in the
watchFiles
list.Anyways, let's focus on the issue at hand. It is simple. The mentioned Guide and associated example doesn't reload the browser with changed code as stated. It needs to be rectified. My PR tries to do that. If there's a different solution let's apply that and rectify the Guide.
alexander-akait commentedon Mar 28, 2022
Please create reproducible repo with example of a problem
webpack-bot commentedon Jun 27, 2022
This issue had no activity for at least three months.
It's subject to automatic issue closing if there is no activity in the next 15 days.
webpack-bot commentedon Jul 12, 2022
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.