Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm run production fails in Laravel Mix with an unknown --hide-modules option

Errorerror: unknown option '--hide-modules'

Short answer

The scripts in your package.json were written for Mix 5, which called webpack directly with flags such as --hide-modules. Mix 6 uses webpack 5, and its CLI no longer accepts those flags. Replace the scripts with the Mix CLI commands, or for a new Laravel project move to Vite.

  • Applies to Laravel Mix 6, webpack 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the scripts block and the installed Mix version. If the scripts call node_modules/webpack/bin/webpack.js with flags, they are the Mix 5 kind.

    grep -n -A8 '"scripts"' package.json
    npm ls laravel-mix
  2. 2Match what you see, then jump to its fix

    1. 1The production script contains --no-progress --hide-modules after node_modules/webpack/bin/webpack.js.The npm scripts still call webpack directly with old flagsFix
    2. 2npm run hot or npm run watch fails with a different unknown flag, such as --inline.The dev-server script keeps another removed flagFix
    3. 3After fixing the scripts, the build fails inside another webpack plugin.The project was upgraded without updating its third-party pluginsFix

What does the error look like?

  • error: unknown option '--hide-modules'
  • Unknown argument: --hide-modules

Cause 1 of 3

The npm scripts still call webpack directly with old flags

1Check

The Mix upgrade guide says the old scripts called webpack with flags such as --hide-modules, --inline and --no-progress, and that the webpack 5 CLI removed a number of options.

grep -n "webpack" package.json

2Fix

Use the scripts from the upgrade guide. They call the Mix CLI, which passes the right options to webpack.

"scripts": {
  "development": "mix",
  "watch": "mix watch",
  "watch-poll": "mix watch -- --watch-options-poll=1000",
  "hot": "mix watch --hot",
  "production": "mix --production"
}

3Verify

Run the production script; it no longer reports the unknown flag.

npm run production

Confirmed by laravel-mix.com

Did this fix it?

Cause 2 of 3

The dev-server script keeps another removed flag

1Check

The guide lists --inline next to --hide-modules among flags the old scripts used; the fix is the same, not adding the flag back.

grep -n -E "inline|hide-modules|no-progress" package.json

2Fix

Replace the script with mix watch --hot; do not carry any old flag over.

"hot": "mix watch --hot"

3Verify

Start the hot reload script.

npm run hot

Confirmed by laravel-mix.com

Did this fix it?

Cause 3 of 3

The project was upgraded without updating its third-party plugins

1Check

Mix 6 ships with webpack 5, PostCSS 8 and Vue Loader 16, so third-party plugins in package.json may not yet support them.

npm ls --depth=0

2Fix

Upgrade Mix with the command from the guide, then update or remove plugins that only support the old versions.

npm install laravel-mix@latest

3Verify

Run the build again.

npm run development

Confirmed by laravel-mix.com

Did this fix it?

How do I stop it coming back?

  • After a Mix major upgrade, rewrite the scripts block first and run each script once.
  • Do not add removed flags back to make an old script pass.
  • For a new Laravel app, start from the Vite setup in the framework docs instead of Mix.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.