32

When I try to compile React component with Laravel Mix in my Laravel project it raises error 2 lifecycle.

E:\MY PROJECTS\Samriddhi Institute> npm run dev

@ dev E:\MY PROJECTS\Samriddhi Institute npm run development

@ development E:\MY PROJECTS\Samriddhi Institute cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/ setup/webpack.config.js

[webpack-cli] Error: Unknown option '--hide-modules' [webpack-cli] Run 'webpack --help' to see available commands and options npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @ development: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=no de_modules/laravel-mix/setup/webpack.config.js npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the @ development 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\RADHESHYAM\AppData\Roaming\npm-cache_logs\2021-09-17T05_52_36_957Z-debug.log npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! @ dev: npm run development npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the @ dev 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\RADHESHYAM\AppData\Roaming\npm-cache_logs\2021-09-17T05_52_37_148Z-debug.log PS E:\MY PROJECTS\Samriddhi Institute>"

Error shown on image

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Ravi Majithiya
  • 321
  • 1
  • 3
  • 3

4 Answers4

79

Update Laravel Mix

npm install --save-dev laravel-mix@latest

Update Your NPM Scripts

If your build throws an error such as Unknown argument: --hide-modules, the scripts section of your package.json file will need to be updated. The Webpack 5 CLI removed a number of options that your NPM scripts was likely referencing.

While you're at it, go ahead and switch over to the new Mix CLI.

Before

"scripts": {
    "dev": "npm run development",
    "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "watch": "npm run development -- --watch",
    "watch-poll": "npm run watch -- --watch-poll",
    "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
    "prod": "npm run production",
    "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},

After

"scripts": {
    "dev": "npm run development",
    "development": "mix",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000",
    "hot": "mix watch --hot",
    "prod": "npm run production",
    "production": "mix --production"
},
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
  • Thank you very much ,i can implement your suggestion and also remove all node modules ,package.lock file and reinstall everything now it's working fine thanks lot again – Ravi Majithiya Sep 18 '21 at 09:58
  • after upgrading the laravel mix to the latest, my prod build CSS is excluding almost all the CSS and outputting a very few styles. Any thoughts on where I can start debugging for that issue? https://stackoverflow.com/questions/70350578/npm-run-prod-is-breaking-the-site – StealthTrails Dec 15 '21 at 17:58
  • I faced the same problem, I used to undo changes(discard using vs-code source control) to my app.css after every build. It saved me. – Dennis Kiprotich Jan 23 '22 at 18:31
  • this solution is not working! – Nadia Jan 31 '22 at 10:28
  • This worked for me. In addition, just make sure that you're using node v16 – Blues Clues Oct 26 '22 at 12:51
  • 1
    This totally worked. Thank you so much for posting this. – Maximus Mar 25 '23 at 21:35
15

I had this issue and solved it by downgrading laravel-mix to

"laravel-mix": "^5.0.9"

then running:

npm install
Yvan Rugwe
  • 618
  • 7
  • 13
0

Remove --hide-modules from your package.json and than run npm run dev it will run without erros.

Ahmed Memon
  • 120
  • 5
-2

In my case i had to switch to node version 14 as i was on 18. My steps.

(1) Check current node version.

nvm list # -->v18.4

(2) Switched to node 14.

nvm use 14.19 

(3) Installed again

npm install

(4) Run dev

npm run dev

It worked.

Africa Matji
  • 345
  • 3
  • 19