Laravel-mix: mix not found

Created on 14 Oct 2020  ·  18Comments  ·  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 6.0.0-beta.10
  • Node Version 12.14.1
  • NPM Version 6.13.6
  • OS: Windows 10

Description:

I am on latest Laravel Homestead. Just did a fresh install of my Homestead box and updated the package.json of my project accordingly. When running npm run development I get this error:

sh: 1: mix: not found

Steps To Reproduce:

npm run development

Most helpful comment

I had the same issue. And it works after run npm install laravel-mix@latest

All 18 comments

Hey, looks like a common issue people are having, @JeffreyWay has posted this reply to a similar issue: https://github.com/JeffreyWay/laravel-mix/issues/2523#issuecomment-704629653

He doesn't even find the mix command, so I assume it is maybe a PATH related Windows VM issue?

Could be?

What's your output of npx mix -p or npx mix

(might be worth taking a quick look over the upgrade docs: https://github.com/JeffreyWay/laravel-mix/blob/master/UPGRADE.md#update-your-npm-scripts)

I am not sure how I'm able to replicate this but I got a new setup too and sometimes this happens. I just simply reinstall and it goes away.

When this happened I checked the laravel-mix in node_modules and it was empty and that's why mix wasn't found.

I'm running into this issue as well, with both Node.js 12.18.0 and 14.3.0. OS is Fedora 33, and I made sure to remove node_modules each time before running yarn to install dependencies.

Laravel Mix is only installed locally, not globally (since that's good practice).

❯ yarn development
yarn run v1.22.0
$ mix
/bin/sh: mix: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

❯ yarn production
yarn run v1.22.0
$ mix --production
/bin/sh: mix: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.


package.json

{
  "private": true,
  "scripts": {
    "development": "mix",
    "doc": "redoc-cli bundle public/developer/v1/openapi.yaml && move-file redoc-static.html public/developer/v1/index.html",
    "hot": "mix --hot",
    "lint": "npm-run-all --sequential lint:css lint:ts",
    "lint:css": "stylelint \"resources/css/**/*.css\"",
    "lint:ts": "eslint \"resources/ts/**/*.ts\"",
    "production": "mix --production",
    "watch": "mix watch",
    "watch-poll": "mix watch -- --watch-options-poll=1000"
  },
  "dependencies": {
    "@barba/core": "^2.9.7",
    "autoprefixer": "^10.0.4",
    "balloon-css": "^1.2.0",
    "cross-env": "^7.0.3",
    "fork-awesome": "^1.1.7",
    "laravel-mix": "^5.0.9",
    "move-file-cli": "^2.0.0",
    "npm-run-all": "^4.1.5",
    "postcss": "^8.1.14",
    "postcss-import": "^13.0.0",
    "postcss-nesting": "^7.0.1",
    "postcss-url": "^10.1.1",
    "redoc-cli": "^0.10.2",
    "resolve-url-loader": "^3.1.2",
    "tailwindcss": "^2.0.1",
    "ts-loader": "^8.0.11",
    "typescript": "^4.1.2",
    "vue-template-compiler": "^2.6.12",
    "webpack": "^5.9.0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^4.9.0",
    "@typescript-eslint/parser": "^4.9.0",
    "eslint": "^7.14.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-plugin-import": "^2.22.1",
    "husky": "^4.3.0",
    "stylelint": "^13.8.0",
    "stylelint-config-standard": "^20.0.0",
    "webpack-cli": "^4.2.0"
  },
  "eslintConfig": {
    "env": {
      "browser": true,
      "es6": true
    },
    "extends": [
      "airbnb-base",
      "eslint:recommended",
      "plugin:@typescript-eslint/eslint-recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:@typescript-eslint/recommended-requiring-type-checking"
    ],
    "rules": {
      "no-alert": "off",
      "no-unused-expressions": "off"
    },
    "globals": {
      "Atomics": "readonly",
      "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
      "project": "./tsconfig.json"
    }
  },
  "stylelint": {
    "extends": "stylelint-config-standard",
    "rules": {
      "at-rule-no-unknown": [
        true,
        {
          "ignoreAtRules": [
            "responsive",
            "screen",
            "tailwind",
            "variants"
          ]
        }
      ]
    }
  },
  "husky": {
    "hooks": {
      "pre-commit": "yarn lint && vendor/bin/php-cs-fixer fix --dry-run --diff"
    }
  }
}


Contents of node_modules/.bin

❯ ls node_modules/.bin
acorn            eslint                json5                       pidtree      svgo
ansi-html        esparse               loose-envify                prettier     swagger2openapi
atob             esvalidate            marked                      purgecss     tailwind
autoprefixer     gonzales              miller-rabin                redoc-cli    tailwindcss
boast            handlebars            mime                        regjsparser  terser
browserslist     he                    mkdirp                      resolve      tsc
concat           html-minifier         move-file                   rimraf       tsserver
cross-env        husky-run             multicast-dns               run-p        uglifyjs
cross-env-shell  husky-upgrade         nanoid                      run-s        uuid
cssesc           import-local-fixture  npm-run-all                 semver       webpack
detective        is-docker             oas-validate                sha.js       webpack-cli
envinfo          js-yaml               opencollective-postinstall  specificity  webpack-dev-server
errno            jsesc                 parser                      stylelint    which


Contents of node_modules/laravel-mix

❯ ls -a node_modules/laravel-mix
icons  LICENSE  node_modules  package.json  readme.md  setup  src

I had the same issue. And it works after run npm install laravel-mix@latest

I am now on 6.0.9 and the issue persists.

@apocalyarts Can you provide your package.json and package-lock.json / yarn.lock file? I can't think of any situation in which the mix binary wouldn't be installed unless explicitly disabled.

@thecrypticace

It is now working in my project and I don't know why. I got curious, if it had to to with me trying to run npm install natively on my Windows Machine, updating and restarting and so on. I tried to reproduce the error and it works like this:

On Homestead (via Virtualbox) on Windows 10:

composer create-project laravel/laravel example-app
cd example-app
npm install --no-bin-links
npm run dev

> sh: 1 : mix: not found

It looks like mix is not correctly installed/found when using Homestead.

If I proceed to delete the node_modules folder and try again using CMD on Windows it's working like a charm:

cd c:\code\example-app
npm install
npm run dev

It's not working because you're installing using --no-bin-links. This explicitly disables creation of the node_modules/.bin folder and will prevent scripts like webpack or mix from working.

It's not working because dependencies in your package.json was'nt installed. run npm cache clean --force and try running npm install again

In my case, the problem was in a project directory where I ran the build. I've added time the directory name so it looked like
my-project-12:23:34.

Colons (":" symbols) caused this error sh: 1 : mix: not found

I renamed directory to smth like my-project-12-23-34 and it solved the issue

This is also happening to me. Fresh Laravel 8.12 installation. Don't have any colons in the folder name, Have tried deleting node_modules, clearing cache and reinstalling via both NPM and Yarn. Have tried updating Laravel Mix to the latest versions.

I'm using --no-bin-links because npm install never works without it.

Mix: Tried multiple 6,0 versions.
Node: 12.19.0
NPM: 7.6.3
OS: Windows 10

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "axios": "^0.21",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.1.14"
    },
    "dependencies": {
        "bootstrap": "^5.0.0-beta2"
    }
}
const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/bootstrap.scss', 'public/css')
    .sass('resources/sass/app.scss', 'public/css')
    .version();

I had the same issue. And it works after run npm install laravel-mix@latest

After hours of trying other suggestions, this comment helped me resolve the issue. Thanks.

I have this issue if I run npm install --production on production server. It seems mix is included only for dev

I had the same issue. And it works after run npm install laravel-mix@latest

it work, i'm using laravel 8 inside docker container via Laradock, thanks!

I had the same issue. And it works after run npm install laravel-mix@latest

this works for me, thank's

Is someone facing issues in js and css files that these are not minifying after this?
I use the following commands

  • npm install laravel-mix@latest
  • npm cache clean -f
  • nvm install 12.14 //Upgrade nodejs version (12.14)
  • npm run dev
    Before the above commands all my files are in minified version.
Was this page helpful?
0 / 5 - 0 ratings