TL:DR; Rails Webpacker1 5.x is not compatible with Webpack Dev Server2 4.x.

What does the issue look like?

The command moved into a separate package: @webpack-cli/serve
Would you like to install serve? (That will run yarn add -D @webpack-cli/serve) (yes/NO) : yes

After running bin/webpack-dev-server in a Rails project

Then after selecting yes and running the bin/webpack-dev-server command again we get

TypeError: Class constructor ServeCommand cannot be invoked without 'new'
...
 return func(...args);
               ^

TypeError: Class constructor ServeCommand cannot be invoked without 'new'

Investigation

The Webpack Dev Server2 has recently been updated from version 3.x to 4.x.

This upgrade seems to have changed the underlying Node command to start the dev server from webpack-dev-server to webpack serve.

Webpacker1 is currently on version 5.4 which has the outdated Webpack Dev Server2 version 3.x syntax.

Webpacker1 is under development and the command has been changed in the upcoming version 6.x as can be seen on the main branch of the repo.

Solution(s)

There are 2 possible solutions to this issue.

  1. Downgrade Webpack Dev Server2 to version 3.x
  2. Upgrade Webpacker1 to (beta) version 6.x

For client/production projects it would be advisable to choose option 1 - downgrading Webpack Dev Server2 to version 3.x

For side projects it should be safe enough to choose option 2 - upgrading Webpacker1 to (beta) version 6.x.

  1. Ruby gem wrapping the JS package Webpack3 - GitHub  2 3 4 5

  2. Underlying JS package used by Webpack3 to run a development server - GitHub  2 3 4 5

  3. Javascript pre-processor - GitHub  2