webpack-cli: Unable to load '@webpack-cli/serve' command

Describe the bug

RedwoodJS’s dev server uses webpack-dev-server under the hood. It broke as soon as @webpack-cli/serve v1.6 was released.

Redwood users start the dev server with yarn rw dev. It runs this command:

cd "${rwjsPaths.web.base}" && yarn cross-env NODE_ENV=development RWJS_WATCH_NODE_MODULES=${
  watchNodeModules ? '1' : ''
} webpack serve --config "${webpackDevConfig}" ${forward}`

Which resolves to something like:

$ /Users/dom/projects/redwood/_sandbox/my-redwood-app/node_modules/.bin/cross-env NODE_ENV=development 
RWJS_WATCH_NODE_MODULES= webpack serve --config /Users/dom/projects/redwood/_sandbox/my-redwood-app/node_modules/@redwoodjs/core/config/webpack.development.js

Our webpack development config can be found here; it’s merged with webpack.common.js, so I’ve included that as well:

What is the current behavior?

Currently, with the new release of @webpack-cli/serve, the dev server doesn’t start up and throws:

web | [webpack-cli] Unable to load '@webpack-cli/serve' command
      [webpack-cli] TypeError: options.forEach is not a function

To Reproduce

Steps to reproduce the behavior:

  1. create a v0.37.2 redwood project using yarn create redwood-app my-redwood-app
  2. run yarn rw dev
  3. observe the error in the console

All together:

$ yarn create redwood-app my-redwood-app
$ cd my-redwood-app
$ yarn rw dev
$ ...
$ web | [webpack-cli] Unable to load '@webpack-cli/serve' command
      [webpack-cli] TypeError: options.forEach is not a function

Expected behavior

The dev server starts up successfully on localhost:8910.

Screenshots

The dev server broken: image The dev server working: image

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: macOS 11.1
    CPU: (8) x64 Apple M1
    Memory: 127.65 MB / 8.00 GB
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /opt/homebrew/bin/yarn
    npm: 7.3.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 94.0.4606.71
    Safari: 14.0.2
  Monorepos:
    Yarn Workspaces: 1.22.10

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 21
  • Comments: 48 (20 by maintainers)

Commits related to this issue

Most upvoted comments

used 4.9.0 instead of 4.8.0 fix me the problem…

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

Sorry for this

Yep, because it is internal package you should have webpack-cli 4.9.0 and do not have @webpack-cli/serve in your package.json, in lock file it should be 1.6.0

FYI, two things you need to do in package.json:

  1. remove @webpack-cli/serve
  2. upgrade webpack-cli to ^4.9.1 (or try the latest one)

Hi, i get a similar issue when i run browserDevelopmentRun target via gradle

This statement in my build.gradle.kts fixes the issue for me

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java) {  
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().versions.webpackCli.version = "4.9.0"
}

Sorry for delay, will have time tomorrow, top on my TODO

@Artur- Can you provide reproducible example? I really can’t reproduce locally Your problem - lock file was updated i.e. now you have @webpack-cli/serve@1.6.0, but uses old verison of webpack-cli@4.8.0, @webpack-cli/serve is internal package and should be updated together with webpack-cli

I am not using webpack-cli 4.9.0. I am using webpack-cli 4.8.0

I am not sure how this advice helps. My package.json is

    "webpack": "4.46.0",
    "webpack-cli": "4.8.0",
    "webpack-dev-server": "4.1.1",
    "webpack-manifest-plugin": "3.0.0",
    "webpack-merge": "4.2.2",

and running

node_modules/.bin/webpack-dev-server 

yesterday resulted in the dev server starting. Today it results in

[webpack-cli] Unable to load '@webpack-cli/serve' command
[webpack-cli] TypeError: options.forEach is not a function
    at WebpackCLI.makeCommand (/.../node_modules/.pnpm/webpack-cli@4.8.0_714d72df2bebb3ac089d7453aabd5d57/node_modules/webpack-cli/lib/webpack-cli.js:173:21)

it helped me “webpack-cli”: “^4.9.1”,

My fix:

package.json

"webpack-cli": "4.9.1",
"webpack-dev-server": "^4.5.0"

webpack.config.js - modify devServer settings to:

// proxy /api to port 8000 during development
  devServer: {
    proxy: {
      "/api": {
       target: "http://127.0.0.1:8000",
        changeOrigin: true,
        secure: false,
        pathRewrite: {
          "^/api": "/api",
        },
      },
    },
    hot: true,
    static: path.resolve(__dirname, "./src/hello_assets")  },
};

Thanks, if the minor versions of the packages truly should go hand in hand maybe you can use ~ instead of ^ to avoid this in the future and still be able to make internal breaking changes

Hi and thank you for your answer, and what about node and npm versions and webpack-dev-server? Thank you!

“webpack”: “5.28.0”, “webpack-cli”: “^4.9.1”, “webpack-dev-server”: “3.11.2”

npm --version 6.14.13

node --version v14.17.3

Thank you @alexander-akait Anything @jtoar and I can do to help — please just let us know. We’re open source maintainers as well and don’t take your effort (or webpack-cli) for granted.

I just followed you on Twitter in case DM’s (or to get on a real-time call) would be helpful to you. You can reach me via DM https://twitter.com/thedavidprice

Overall, I think the semver ^ is the reason this is a cascading issue: https://github.com/webpack/webpack-cli/blob/74089ce03c3cb4842d188f0a3a749c2c173ac84e/packages/webpack-cli/package.json#L35

imho I’d highly recommend pinning each dependency in that package.json

Thanks, I will looking at this tomorrow (busy right now), maybe do patch release to avoid problem

update your package.json “webpack-cli”: “4.9.0”, “webpack-dev-server”: “^4.4.0”,

@jtoar Here https://github.com/webpack/webpack-cli/issues/2990#issuecomment-937948234 is the same problem as I described above, webpack-cli is 4.8.0, but @webpack-cli/serve is 1.6.0 (you need update webpack-cli to 4.9.0 version), I can do patch release and release 4.8.1, but it will not help and will not solve the problem, because you pin your dev deps (strongly recommend avoid it, lock files were created to avoid installation new versions on the each installation, but pinning them doesn’t allow developers get fixes, especial security, which released as patch), looks at node_modules/@redwoodjs/internal/package.json, and you will see "webpack-cli": "4.8.0",, to be honestly I don’t understand how I can help to fix problem, yes, we do small breaking change in internal package, sorry for this, but I think will be better to update webpack-cli to the latest stable version, i.e. 4.9.0. Feel free to feedback.

And how @webpack-cli/serve appears in your deps, we never ask that in our docs…

Hi, i get a similar issue when i run browserDevelopmentRun target via gradle, which calls @webpack-cli/serve. I was tinkering around with KotlinJs. Seems, that 1.6.0 broke the build. Until then, everything worked fine for me.

[webpack-cli] Unable to load '@webpack-cli/serve' command [webpack-cli] TypeError: options.forEach is not a function [webpack-cli] TypeError: options.forEach is not a function at WebpackCLI.makeCommand (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\lib\webpack-cli.js:173:21) at ServeCommand.apply (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\node_modules\@webpack-cli\serve\lib\index.js:41:19) at loadCommandByName (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\lib\webpack-cli.js:907:35) at async Command.<anonymous> (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1462:17) at async Promise.all (index 0) at async WebpackCLI.run (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1500:9) at async runCLI (D:\Workspace\clsky.de\build\js\node_modules\webpack-cli\lib\bootstrap.js:11:9)

I also experienced this issue. Multiple reports from other people with the same error.

Manually pinning (and setting resolution) this package to v1.52.0 is the workaround.