Israel Juarez
Israel Juarez

Reputation: 121

Unable to load @webpack-cli/serve

I downloaded a project folder from a pluralsight tutorial, when I try to run it with npm start it shows this message:

[webpack-cli] Unable to load '@webpack-cli/serve' command [webpack-cli] TypeError: options.forEach is not a function at WebpackCLI.makeCommand (C:\Users\Israel Juarez\Desktop\before\node_modules\webpack-cli\lib\webpack-cli.js:173:21)

at ServeCommand.apply (C:\Users\Israel Juarez\Desktop\before\node_modules\@webpack-cli\serve\lib\index.js:41:19)

at loadCommandByName (C:\Users\Israel Juarez\Desktop\before\node_modules\webpack-cli\lib\webpack-cli.js:907:35)
at async Command.<anonymous> (C:\Users\Israel Juarez\Desktop\before\node_modules\webpack-cli\lib\webpack-cli.js:1462:17)
at async Promise.all (index 0)
at async WebpackCLI.run (C:\Users\Israel Juarez\Desktop\before\node_modules\webpack-cli\lib\webpack-cli.js:1500:9)

at async runCLI (C:\Users\Israel Juarez\Desktop\before\node_modules\webpack-cli\lib\bootstrap.js:11:9)

npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! [email protected] start: webpack serve --config webpack.config.dev.js --port 3000 npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the [email protected] start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\Israel Juarez\AppData\Roaming\npm-cache_logs\2021-10-20T17_42_05_820Z-debug.log

Upvotes: 11

Views: 18587

Answers (5)

Maksym Dudyk
Maksym Dudyk

Reputation: 1164

You should uninstall your version of webpack-cli by:

npm uninstall webpack-cli

Then bump your version of webpack-cli by:

npm install webpack-cli --save-dev

That might help. Also check you don't have @webpack-cli/serve included in package.json directly.

Upvotes: 21

The Ali
The Ali

Reputation: 1

I ran to the same problem in my project. In my case, I first delete package-lock.json both in root and ./node_modules directory, then run the following code

npm install --save --legacy-peer-deps [email protected]

This error happens to be related to the version of webpack-cli used in projects.

Upvotes: 0

usertest
usertest

Reputation: 2262

from the authors comment on the issue:

Looks like we have small regression here, but if we revert it, it will create another breaking change, so my recommendation - bump [email protected] and update lock file, also check you don't have @webpack-cli/serve in package.json directly.

Sorry for this

I changed the version from 4.5.0 to 4.9.0 and it the dev server starts as expected.

Thanks to @Henry Story for the issue link.

Upvotes: 1

fran-ol
fran-ol

Reputation: 1

Add mode: 'development' into your config file.

module.exports = {
     mode: 'development',
     ...
    };

OR

type CLI argument and verify on file:

webpack --mode=development

Also, you can either choose 'development', 'production' or 'none'.

Upvotes: 0

hussi07
hussi07

Reputation: 9

run these commands

  • npm install webpack
  • npm install --save-dev webpack-cli

Hope the issue will get resolved.

Upvotes: 0

Related Questions