1

I am following this video https://www.youtube.com/watch?v=zEPYSNO7o3Q

And I got error in npm run dev

This is the solution I try:

Step1: composer update
Step2: rm -rf node_modules
Step3: npm cache clean
Step4: npm install
Step5: npm outdated
Step6: npm install
Step7: npm run dev

But I still get this error:

> @ development C:\laragon\www\lara6
> cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules -- 
config=node_modules/laravel-mix/setup/webpack.config.js

'cross-env' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ development: `cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js -- 
progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js`
npm ERR! Exit status 1
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\mmagante\AppData\Roaming\npm-cache\_logs\2020-01-22T03_04_02_064Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `npm run development`
npm ERR! Exit status 1
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.

I am currently using:

php artisan --version - Laravel Framework 6.12.0

node -v - v12.14.1

npm -v - 6.13.6

php -v - PHP 7.2.19

I also find this link and still not working: https://github.com/JeffreyWay/laravel-mix/issues/1072

Mathew Magante
  • 1,280
  • 3
  • 19
  • 28
  • i hava same problem and change node downgrade to v10.16.3 and do work – sajjad Jan 22 '20 at 03:57
  • i worked with this configuration => npm 6.9.0 , node 10.16 don't need php version – sajjad Jan 22 '20 at 03:58
  • @sajjad can you show me what you exactly you do? i try do downgrade my npm and node but still I get the error – Mathew Magante Jan 22 '20 at 05:20
  • Does this answer your question? [Laravel 5.4 ‘cross-env’ Is Not Recognized as an Internal or External Command](https://stackoverflow.com/questions/45034581/laravel-5-4-cross-env-is-not-recognized-as-an-internal-or-external-command) – julianstark999 Jan 22 '20 at 05:38
  • @JulianS no, that answer is too old and not working for me, I already try that sir – Mathew Magante Jan 22 '20 at 05:39
  • I solve this by getting a working node_module in my old project,and paste it to my current project, but when I am using install npm again, this error occurred again. – Mathew Magante Feb 18 '20 at 08:48

3 Answers3

3

Had a somewhat similar issue, npm run watch was not working on my end but it was not giving any error like that. Possible that you may need to install/reinstall cross-env first.

npm install cross-env

If npm run watch is still not working after that but with no errors, try the following:

  1. install webpack again (no need to remove)

npm install webpack

  1. in package.json, replace

"watch": "npm run development -- --watch",

with

"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",

Possible that you do not need to do step 1. Just posted the steps I did to make it work on my end. Hope this helps someone since, I have been getting great answers in stackoverflow for quite sometime now, time to give back whenever I can.

2

Delete node_modules folder from your project.

Run npm install --global cross-env this command.

Delete "cross-env": "^5.0.1", From package.json file devDependencies section.

Run npm install --no-bin-links

Now run npm run dev

Mahfujur Rahman
  • 157
  • 2
  • 10
  • Why do you propose to install the dependency as a global instead of locally? – pintxo Aug 16 '20 at 14:55
  • @pintxo, I am not OP but I was getting the same error even with cross-env in my package.json but it worked once I installed cross-env globally. – l3fty Oct 25 '20 at 06:28
-1

Add this to your package.json:

"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"
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jul 12 '22 at 15:12