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

node.jsLaravelNpmLaravel Mix

node.js Problem Overview


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.

node.js Solutions


Solution 1 - node.js

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

  1. 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.

  2. run

>npm install --no-bin-links

  1. 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.

Solution 2 - node.js

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

Solution 3 - node.js

Following these steps solved my problem.

  1. Delete node_modules directory
  2. Delete package-lock.json file
  3. Start command prompt as Administrator <- important
  4. Run npm install
  5. Run npm run dev

Solution 4 - node.js

You are getting the error because you might not have run the command npm install first.

i.e. First, run npm install and then npm run dev

Solution 5 - node.js

There is the same problem in Linux OS. The issue is related on Windows OS, but Homestead is a Ubuntu VM, and the solution posted works strongly good in others SO. I applied the commands sugested by flik, and the problems was solved. I only used the following commands

I only used the following commands

rm -rf node_modules
npm cache clear --force

After

npm install cross-env
npm install 
npm run watch

It's working fine on linux Fedora 25.

Solution 6 - node.js

According to this issue comment, editing cross-env path will fix the problem. Change cross-env to node node_modules/cross-env/dist/bin/cross-env.js in package.json like this:

    "dev": "npm run development",
    "development": "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": "npm run watch -- --watch-poll",
    "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",
    "prod": "npm run production",
    "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"

Solution 7 - node.js

For me simply run:

npm install cross-env

was enough

Solution 8 - node.js

Your error states that cross-env is not installed.

'cross-env' is not recognized as an internal or external command, operable program or batch file.

You just need to run

npm install cross-env

Solution 9 - node.js

The following worked for Laravel 7.x (and should probably work for any other version as well given the nature of the issue).

npm uninstall --save-dev cross-env
npm install -g cross-env

Just moving cross-env from being a local devDependency to a globally available package.

Solution 10 - node.js

Just npm install --save-dev cross-env in the root directory of your project.

Solution 11 - node.js

Before try running npm run dev please run npm install --no-bin-links in the project directory, this will install all required packages. Also check this link for compiling instruction. https://laravel.com/docs/5.4/mix

Also double check in your conf file, wherever you find something like this

(something)/cross-env/bin/(something)

change it to

(something)/cross-env/dist/bin/(something)

If you are using homestead, in package.json paste this

{
  "private": true,
  "scripts": {
    "dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "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",
    "watch-poll": "cross-env 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": "cross-env 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": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  },
  "devDependencies": {
    "axios": "^0.15.3",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.3",
    "jquery": "^3.1.1",
    "laravel-mix": "^0.8.1",
    "lodash": "^4.17.4",
    "vue": "^2.1.10"
  }
}

Also check this link https://github.com/JeffreyWay/laravel-mix/issues/478

Solution 12 - node.js

This worked for me (on Windows 10):

  1. Add the following lines into your scripts in the package.json file:

     "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 --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"
    
  2. Make your devDependencies looks something like this:

     "devDependencies": {
         "axios": "^0.18",
         "bootstrap": "^4.0.0",
         "popper.js": "^1.12",
         "cross-env": "^5.1",
         "jquery": "^3.2",
         "laravel-mix": "^2.0",
         "lodash": "^4.17.4",
         "vue": "^2.5.7"
     }
    
  3. Remove node_modules folder

  4. Run npm install

  5. Run npm run dev

Solution 13 - node.js

I think this log entry Local package.json exists, but node_modules missing, did you mean to install? has gave me the solution.

npm install && npm run dev

Solution 14 - node.js

Simply try running npm install / yarn etc first before running npm start / yarn start as @only4 mentioned, if you see this problem, as it means your .env is not in sync with your package.json, i.e. you installed a package but not quite configured it or other way around

Solution 15 - node.js

Delete the node_modules folder

Then you should run the commands:

npm install --no-bin-links

npm run dev

It's worked on my Laravel 5.5 and Windows.

Solution 16 - node.js

Try to run npm run dev in powershell. This worked for me.

Solution 17 - node.js

I real all the solution but there is not a standard solution...

JUST REMOVE NODEJS AND INSTALL THE LATEST VERSION OF NODEJS

instead of many bad shortcut solutions.

Solution 18 - node.js

I finally got it to work by following these steps:

  1. Remove the file package-lock.json
  2. Run the command: npm install --force
  3. Try again to execute npm start

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArthur TarasovView Question on Stackoverflow
Solution 1 - node.jsYevgeniy AfanasyevView Answer on Stackoverflow
Solution 2 - node.jsflikView Answer on Stackoverflow
Solution 3 - node.jscollinView Answer on Stackoverflow
Solution 4 - node.jsNaveed AliView Answer on Stackoverflow
Solution 5 - node.jsAlexandre SiqueiraView Answer on Stackoverflow
Solution 6 - node.jsHafez DivandariView Answer on Stackoverflow
Solution 7 - node.jsLuca C.View Answer on Stackoverflow
Solution 8 - node.jsMike StrattonView Answer on Stackoverflow
Solution 9 - node.jsAndrey IgnatyevView Answer on Stackoverflow
Solution 10 - node.jsurvi sharmaView Answer on Stackoverflow
Solution 11 - node.jsonly4View Answer on Stackoverflow
Solution 12 - node.jsGevorg MelkumyanView Answer on Stackoverflow
Solution 13 - node.jsAhmad Rasyid SalimView Answer on Stackoverflow
Solution 14 - node.jssedView Answer on Stackoverflow
Solution 15 - node.jsNirmal KhadkaView Answer on Stackoverflow
Solution 16 - node.jsGevorg MelkumyanView Answer on Stackoverflow
Solution 17 - node.jsuser3562771View Answer on Stackoverflow
Solution 18 - node.jsAvinash BView Answer on Stackoverflow