-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails to update index.js when using webpack-dev-server #15477
Comments
please create reproducible repo. from your description unclear what is a problem, maybe you just need to remove |
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 |
In the [Development Guide under Using Watch Mode section] (https://webpack.js.org/guides/development/#using-watch-mode) the content says: >The only downside is that you have to refresh your browser in order to see the changes. It would be much nicer if that would happen automatically as well, so let's try webpack-dev-server which will do exactly that. 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. The devServer configuration as mentioned will not refresh the browser. To actually refresh the page the minimum configuration that needs to be added to devServer is `watchFiles: ['./src/**/*.*']` Fixes: webpack/webpack#15477
What do you mean - |
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 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. |
Please create reproducible repo with example of a problem |
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. |
Issue was closed because of inactivity. If you think this is still a valid issue, please file a new issue with additional information. |
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,
},
};
The text was updated successfully, but these errors were encountered: