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

Viewed 150006

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.

18 Answers

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

For me simply run:

npm install cross-env

was enough

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

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.

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

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

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

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.

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

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.

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
Related