Laravel Mix "sh: 1: cross-env: not found error"

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
In this blog post, we will discuss the common sh: 1: cross-env: not found error encountered when using Laravel Mix in Laravel projects. We will provide an explanation of this issue and offer possible solutions to help you resolve it efficiently. Let's dive into the root causes and fixes for this error. #### Understanding the Symptoms and Causes When running any npm run command in your project, you might encounter issues related to packages or the environment setup. Some of the common symptoms include: 1. The Laravel Mix configuration doesn't load correctly, preventing webpack tasks from working as expected. 2. NPM commands fail due to missing node_modules dependencies or incorrect package versions. 3. A missing cross-env package in your project's package.json file. Now let's delve into how these symptoms are connected: - Missing packages: Laravel Mix is a handy tool that allows you to compile JavaScript and build your frontend assets with Webpack. Sometimes, it might not load correctly because of missing or outdated dependencies in the package.json file. - Cross-env issues: The cross-env package is used in Laravel Mix tasks to preserve environment variables when executing Node.js commands. This helps prevent environment leaks while running specific tasks. When an error like sh: 1: cross-env: not found appears, it suggests that the cross-env package might be missing or misconfigured in your project. #### Diagnosing and Repairing the Issue with NPM Commands To fix this issue and resolve the sh: 1: cross-env: not found error, you can try following these steps: 1. Verify that Laravel Mix is installed correctly by using npm install --dev laravel-mix@latest. If you already have it installed, update Laravel Mix to the latest version with npm update laravel-mix@latest. 2. Check your package.json file for missing dependencies or incorrect versions. Ensure that all necessary packages (cross-env included) are listed under the devDependencies section of your package.json. If cross-env is not already present, install it with npm install --save-dev cross-env@latest. 3. Run npm run dev to check if the Laravel Mix command loads correctly. In case of errors or inaccurate configuration files, consider creating a new Laravel project and copying over the needed folders (resources, assets, etc.). Rerun npm install --dev to rebuild your dependencies and try again. 4. If the issue persists, you may need to check if your Vagrant box has the correct environment setup for Node.js. Ensure that the latest version of Node.js is installed on your machine and try running an npm command like npm install --global cross-env@latest to install the missing package globally. #### Conclusion The sh: 1: cross-env: not found error can be a result of issues with Laravel Mix, packages, or environment setup. Carefully follow all the steps mentioned above to diagnose and resolve this problem in your Laravel project. Always ensure that you have the latest versions of dependencies installed and update both Laravel Mix and npm regularly to avoid similar errors. If none of these steps work for you, consider seeking help from the Laravel community or contacting support at https://laravelcompany.com for further assistance.