webpack-dev-server stops compiling after a syntax error, requires restart

Viewed 997

My webpack-dev-server normally works as it should, live updates are working, everything's great.

However, if I ever save a file with a syntax error, the server stops compiling and requires me to restart it to get it working again.

For example, say I accidentally add an extra comma to a .scss file, the webpack-dev-server outputs the error:

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Invalid CSS after '...oto Condensed",': expected expression (e.g. 1px, bold), was ", sans-serif;"
        on line 18 of /Users/r/Documents/sol/src/styles/app.scss
>>   font-family: "Roboto Condensed",, sans-serif;

   ----------------------------------^

 @ ./src/styles/app.scss 2:26-181
 @ ./src/index.jsx
ℹ 「wdm」: Failed to compile.

But when I fix the error by removing the comma and save the file, the server doesn't recompile like it normally does (it doesn't seem to output anything at all). I have to kill the webpack-dev-server and restart it.

The closest thing I've found online to my issue was this https://github.com/webpack/webpack-dev-server/issues/463, but the solutions there didn't fix my issue.

Here is my webpack.config.js:

const path = require('path');

module.exports = {
    entry: path.resolve(__dirname, 'src', 'index.jsx'),

    output: {
        path: path.resolve(__dirname, 'output'),
        filename: 'bundle.js'
    },

    devServer: {
        publicPath: '/output/',
        contentBase: path.resolve(__dirname, 'src'),
    },
    resolve: {
        extensions: ['.js', '.jsx']
    },
    module: {
        rules: [
            {
                test: /\.jsx/,
                use: {
                    loader: 'babel-loader',
                    options: { presets: ['@babel/preset-react', '@babel/preset-env'] }
                }
            },
            {
                test: /\.scss/,
                use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
            }
        ]
    }
};

Is it normal behavior for the server to stop compiling after an error? Or is there a flag I can change so I don't have to restart the server after every syntax error?

1 Answers

I'm not sure if this is relevant to your webpack config, but I had the same issue until I removed the prettier and prettier-webpack-plugin plugin. I noticed that was where the crash was happening in my logs:

✖ 「wdm」: SyntaxError: Unexpected token (100:3)
   98 | // cull whenever the viewport moves
   99 | PIXI.Ticker.shared.add(() =>
> 100 |   if (viewport.dirty) {
      |   ^
  101 |     if (viewport.top < chunk.top) loadChunk('top');
  102 |     if (viewport.left < chunk.left) loadChunk('left');
  103 |
    at t (./node_modules/prettier/parser-babel.js:1:379)
    at Object.parse (./node_modules/prettier/parser-babel.js:1:346226)
    at Object.parse (./node_modules/prettier/index.js:13625:19)
    at coreFormat (./node_modules/prettier/index.js:14899:14)
    at format (./node_modules/prettier/index.js:15131:14)
    at ./node_modules/prettier/index.js:57542:12
    at Object.format (./node_modules/prettier/index.js:57562:12)
    at ./node_modules/prettier-webpack-plugin/index.js:70:47
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:69:3)
ℹ 「wdm」: wait until bundle finished: /
ℹ 「wdm」: wait until bundle finished: /```
Related