39

Guys can you please help me on this I have trouble run npm run dev for my Laravel Mix. I followed links below but still error exist. Do i have a problem on my OS? I tried to remove node_modules, run npm install --global cross-env. and run NPM install again.

https://github.com/JeffreyWay/laravel-mix/issues/478

Laravel 5.4 'cross-env' is not recognized as an internal or external command

Here are my versions:

  • Laravel mix version: ^2.0
  • Node Version (node -v): 8.9.0
  • NPM Version (npm -v): 5.6.0
  • OS: Windows7
  • XAMPP
> @ development C:\xampp\htdocs\codetinerant
> 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\Garciano\AppData\Roaming\npm-cache\_logs\2018-02-17T10_08_34_901Z-debug.log
Jesray Garciano
  • 413
  • 1
  • 4
  • 9

6 Answers6

91

First, run:

rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force

Then run the command

npm install cross-env

npm install 

and then you can also run

npm run dev
flik
  • 3,433
  • 2
  • 20
  • 30
  • The ease and smooth way to handle that. Thank you! – Pedro Cardoso Dec 11 '20 at 02:44
  • Use powershell for install `npm-install` – ApsaraAruna Sep 04 '21 at 16:34
  • I tried 2 times but that above solution not works for me. then I found another solution at github issues ... simply run `npm install --save-dev cross-env` command then my problem has solved... https://github.com/gothinkster/react-redux-realworld-example-app/issues/97 – Harsh Patel Oct 16 '21 at 06:07
17

Did you try specifying the path to cross-env as suggested by dwoodward on the Github issue you linked. This goes in your package.json file:

"dev": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --watch-poll --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"

This may have changed in more recent versions of Laravel but the gist is that you should change cross-env to node_modules/cross-env/dist/bin/cross-env.js.

Jonathon
  • 15,873
  • 11
  • 73
  • 92
4

Try install cross-env globally.

run

sudo npm i -g cross-env
Apit John Ismail
  • 2,047
  • 20
  • 19
0

Try install cross-env:

npm install cross-env
Carlos Noé
  • 103
  • 3
  • 11
-1

Try Add the npm bin directory to your system path e.g C:\Users\DELL\AppData\Local\Yarn\bin

myckhel
  • 800
  • 3
  • 15
  • 29
-1

I resolved it by uninstalling node and then running the following command.

npm install -d
Karl Hill
  • 12,937
  • 5
  • 58
  • 95