webpack-dev-server: webpack-dev-server stops watching files for changes on .js syntax error
- Operating System: Windows 10
- Node Version: v14.16.1
- NPM Version: 6.14.12
- webpack Version: 5.31.0
- webpack-dev-server Version: 3.11.2
- Browser: Version 89.0.4389.114 (Official Build) (64-bit)
- This is a bug
Code
const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ESLintPlugin = require('eslint-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
const isDev = !isProd
const filename = (ext) =>
isDev ? `bundle.${ext}` : `bundle.[fullhash].${ext}`
module.exports = {
context: path.resolve(__dirname, 'src'),
mode: 'development',
entry: ['@babel/polyfill', './index.js'],
output: {
filename: filename('js'),
path: path.resolve(__dirname, 'dist'),
clean: true,
},
resolve: {
extensions: ['.js'],
alias: {
'@': path.resolve(__dirname, 'src'),
'@core': path.resolve(__dirname, 'src/core'),
},
},
devtool: isDev ? 'source-map' : false,
devServer: {
port: 8080,
hot: isDev,
watchContentBase: true,
},
plugins: [
new ESLintPlugin(),
new HTMLWebpackPlugin({
template: 'index.html',
filename: 'index.html',
minify: {
removeComments: isProd,
collapseWhitespace: isProd,
},
}),
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'src/favicon.ico'),
to: path.resolve(__dirname, 'dist'),
},
],
}),
new MiniCssExtractPlugin({
filename: filename('css'),
}),
],
target: 'web',
module: {
rules: [
{
test: /\.s[ac]ss$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
}
deps:
{
"devDependencies": {
"@babel/core": "^7.13.14",
"@babel/eslint-parser": "^7.13.14",
"@babel/preset-env": "^7.13.12",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^8.1.0",
"cross-env": "^7.0.3",
"css-loader": "^5.2.0",
"eslint": "^7.23.0",
"eslint-config-google": "^0.14.0",
"eslint-webpack-plugin": "^2.5.3",
"html-webpack-plugin": "^5.3.1",
"mini-css-extract-plugin": "^1.4.0",
"sass": "^1.32.8",
"sass-loader": "^11.0.1",
"webpack": "^5.31.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "v3.11.2"
},
"dependencies": {
"@babel/polyfill": "^7.12.1",
"normalize.css": "^8.0.1"
}
}
index.js
console.log('working!')
cosole.log('working!') // trigger an error
Expected Behavior
webpack-dev-server successfully refreshes the page or places in changes
Actual Behavior
A syntax error breaks watching files and webpack-dev-server stops showing any new changes (but compiles them, terminal tells this) until the page is refreshed manually with F5
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 37 (21 by maintainers)
It is fixed in
webpack-dev-server@4-beta
, we have thewatchFiles
optionI tried making it on the sandbox but I can’t for the death of me make it run, if you can figgure it out, be my guest: https://codesandbox.io/s/webpack-sample-ub8ue?file=/webpack.config.js
alternatively, find it on my github: https://github.com/DelliriumX/webpack-reload-clone
It is a bit convoluted, but I’ve cut away a lot of the custom build thing out of it so some things might not make much sense, still doesn’t work. I am not sure if my start script (
package-json
) or devServer config is correct, but it refuses to reload, I am open to suggestions.I can try to mock something up but will take some time, as the entire thing is super convoluted, give me 10 minutes or so to try to scrape from where I am and get it up as a new repo
I need investigate, WIP on this
Bug, we need to set
optimization.emitOnErrors: false
whenhmr
enabled by default, workaround:I think you need to use
watchFiles
option. https://github.com/webpack/webpack-dev-server/blob/e80976320d21f43e0512375d3811c8b09e705007/lib/options.json#L493