Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Brand new Rails 6.1.4.1 fails with webpack error - TypeError: Class constructor ServeCommand cannot be invoked without 'new'

A brand new Rails 6.1.4.1 app fails to run bin/webpack-dev-server with the following error:

/rails_app/node_modules/webpack-cli/bin/utils/prompt-command.js:46
    return func(...args);
           ^

TypeError: Class constructor ServeCommand cannot be invoked without 'new'
    at runWhenInstalled (/rails_app/node_modules/webpack-cli/bin/utils/prompt-command.js:46:9)
    at promptForInstallation (/rails_app/node_modules/webpack-cli/bin/utils/prompt-command.js:140:10)
    at /rails_app/node_modules/webpack-cli/bin/cli.js:32:43
    at Object.<anonymous> (/rails_app/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
like image 702
Scott K Avatar asked Sep 03 '21 14:09

Scott K


1 Answers

This reported issue shows that webpack-dev-server is no longer compatible with Webpacker 5. This means that there are two fixes available to us:

  1. Force webpack-dev-server to stay on version 3

You can do this by updating your package.json file:

"webpack-dev-server": "~3"
  1. Upgrade to Webpacker 6

This version is not yet released and the upgrade path is not simple.

like image 124
James Chevalier Avatar answered Nov 15 '22 14:11

James Chevalier