how to fix cross-env error in laravel

how to fix cross-env error in laravel

7,610

Sometimes you might face 'cross-env' is not recognized as an internal or external command, operable program or batch file. error when you try to install npm in laravel. Today I'll show you how to fix that.

Solution 1

First of all if you are windows user consider to install npm with this command

npm install --no-bin-links

if you already installed npm in different way (on Windows) I suggest you to remove node_modules folder and install it with command above.

After you installed NodeJs successfully in your laravel project go ahead and open package.json file.

Next replace Scripts part with codes below

JSON


"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",
        "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": "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",
        "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"

Now run


npm run watch

Solution 2

1- remove node_modules folder

2- run npm install --global cross-env

3- run npm install --no-bin-links

4- run npm run dev

Tested on Windows 10 with Laravel-5.4 Laravel-5.4 Laravel-5.6

Now you can use your node modules in your application.

- Last updated 4 years ago

Ads

Be the first to leave a comment.

You must login to leave a comment