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

前端 未结 16 1099
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 17:04

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 -         


        
相关标签:
16条回答
  • 2020-11-29 17:56

    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
    
    0 讨论(0)
  • 2020-11-29 17:57

    For me simply run:

    npm install cross-env
    

    was enough

    0 讨论(0)
  • 2020-11-29 17:57

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

    0 讨论(0)
  • 2020-11-29 17:59

    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.

    0 讨论(0)
  • 2020-11-29 17:59

    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
    0 讨论(0)
  • 2020-11-29 18:03

    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
    0 讨论(0)
提交回复
热议问题