Laravel Mix “sh: 1: cross-env: not found error”

柔情痞子 提交于 2019-12-02 17:54:07

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

run

$ sudo npm install --global cross-env

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

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

If the solutions above didn't work, refresh node_modules using
rm -rf node_modules && npm install
this worked for me

You do need to check if cross-env module is installed. If not, run:

npm install cross-env

But you need it to be recognized as a "command". Patching the path as proposed by the accepted answer (or is it?) led me further, but still gave me an error.

The solution for me was to reload vagrant "vagrant reload --provision", and reset my ssh / putty session.

kangular

Sometimes deleting the /node_modules and running

npm install 

will solve issues like this one.

If you are just desperate of fixing this error like my case, just remove cross-env from you package.json and run laravel mix without it ..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!