Laravel Mix "sh: 1: cross-env: not found error"

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

run

$ sudo npm install --global cross-env

--- update ---

But, my advice is to avoid executing npm run ... on the guest homestead, because it is very slow and because there is no benefit in it.

No matter where you build the assets they are going to be executed in the browser. So you better install npm on your host computer and build the assets there.


First check if cross-env module is installed. If not, run:

npm install cross-env

After that you need to go to the node_modules folder. Then find cross-env folder. Go inside and find cross-env.js.

In my case it was node_modules/cross-env/dist/bin/cross-env.js

You need to change path to cross-env.js in scripts section in your package.json file.

{
  "private": true,
  "scripts": {
    "dev": "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_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",
    "hot": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "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"
  },

........

}

Run:

npm install

Then try again.


If the solutions above didn't work, refresh node_modules using

rm -rf node_modules && npm install

this worked for me


There are couple of ways to solve this error.

  • Delete node_modules folder then do npm install again. if it doesn't solve then:

  • You can install as dev dependency by firing

npm install --save-dev cross-env

if it doesn't solve then:

  • Install cross-env globally as npm install --g cross-env It will install it in \Users\Roaming\npm modules. Then I suggest you can close your shell and open it again & fire the command.

if it doesn't solve then: - in Package.json you can use like:

node node_modules/dist/bin/cross-env cross-env ...