Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 ‘cross-env’ Is Not Recognized as an Internal or External Command

I'm trying to run npm run dev for Laravel Mix and I get this error:

> @ dev D:\projects\ptcs > cross-env NODE_ENV=development webpack --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! @ dev: `cross-env NODE_ENV=development webpack --progress --hide- modules --config=node_modules/laravel-mix/setup/webpack.config.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ dev script. 

I updated node.js to 6.11.0 and npm to 5.2.0, but it didn't help. I'm running Homestead on Windows 7.

like image 473
Arthur Tarasov Avatar asked Jul 11 '17 12:07

Arthur Tarasov


People also ask

How do I use cross-env in node js?

Because you have it installed in node_modules. If you want to use it outside, you would need to do npm install --global cross-env to use it anywhere. Just because you're cd'd n the project does not mean you will be able to use commands inside node_modules . ./node_modules/. bin/cross-env should also work.

Is not recognized as an internal or external command npm run build?

To solve the error "'concurrently' is not recognized as an internal or external command, operable program or batch file", install the package globally by running npm install -g concurrently , restart your terminal and make sure your PATH environment variable is set up correctly.

Is not recognized as an internal or external command Nodemon?

Use npx to solve the error "'nodemon' is not recognized as an internal or external command, operable program or batch file", e.g. npx nodemon server. js or install the package globally by running npm install -g nodemon and make sure your PATH environment variable is set up correctly.


1 Answers

You need to make cross-env working globally instead of having it in the project.

1) remove node_modules folder

2) run

npm install --global cross-env

3) remove "cross-env": "^5.0.1", from package.json file devDependencies section. Actually, you can skip this step and keep package.json intact. If you prefer.

4) run

npm install --no-bin-links

5) run

npm run dev

and see it working

P.S Tested on Windows 10 with Laravel-5.4

P.P.S Windows 10 with Laravel-5.6 does not have this problem, thus updating is an alternative solution.

like image 96
Yevgeniy Afanasyev Avatar answered Nov 08 '22 18:11

Yevgeniy Afanasyev