When working with Laravel, you may come across an error that says “‘mix’ is not recognized as an internal or external command.” This error occurs when you’re trying to run a mix-related command, such as npm run dev
, and Laravel Mix is not properly configured or installed.
In this tutorial, you will learn how to fix or resolve laravel ‘mix’ is not recognized as an internal or external command.
laravel ‘mix’ is not recognized as an internal or external command
Steps to resolve laravel ‘mix’ is not recognized as an internal or external command:
- Step 1: Verify Node.js and NPM Installation
- Step 2: Check Environment Path (Windows)
- Step 3: Navigate to Your Laravel Project Directory
- Step 4: Install Laravel Mix
Step 1: Verify Node.js and NPM Installation
Open your terminal or cmd and run the following command into it to verify that Node.js and NPM are properly installed on your system:
node -v npm -v
Step 2: Check Environment Path (Windows)
If you are using Windows and still face the issue, you might need to check your environment variables. The error message you’re encountering indicates that your system can’t find the Mix executable. Here’s how you can fix it:
- Open the Windows Start Menu.
- Search for “Environment Variables” and select “Edit the system environment variables.”
- In the System Properties window, click the “Environment Variables” button.
- In the “User variables” section, locate the “Path” variable and click “Edit.”
- Ensure that the path to the
node_modules/.bin
directory within your Laravel project is included. It should look something like this:- C:\path\to\your\laravel\project\node_modules.bin
- Click “OK” to save your changes.
- Close and reopen your terminal or command prompt to apply the changes.
$this->app->bind('path.public', function() { return base_path().'/../public_html'; });
Step 3: Navigate to Your Laravel Project Directory
Open your terminal or command prompt and navigate to your Laravel project’s root directory:
cd /path/to/your/laravel/project
Step 4: Install Laravel Mix
Now, run the following command on terminalf or cmd to install the latest version of Laravel Mix.
npm install laravel-mix@latest --save-dev
Conclusion
That’s it! You should now be able to use Laravel Mix for asset compilation without encountering the “‘mix’ is not recognized” error.