While use run npm run dev
command and get error message “‘cross-env’ is not recognized as an internal or external command” in a Laravel project, it’s commonly related to an issue with your environment variables or the misconfiguration of your project.
In this tutorial, you will learn how to fix laravel ‘cross-env’ is not recognized as an internal or external command error, and set the PATH environment variable.
How to Fix ‘cross-env’ is not recognized as an internal or external command in Laravel
Here are steps:
Step 1: Delete node_modules Directory
Firstly, open your cmd or terminal and run the following command into it to remove or delete node_moduel directory from your project:
For Linux and Mac user:
# for macOS and Linux rm -rf node_modules rm -f package-lock.json rm -f yarn.lock npm cache clean --force
For Windows user:
# for Windows
rd /s /q "node_modules"
del package-lock.json
del -f yarn.lock
npm cache clean --force
Step 2: Reinstall cross-env
Run the following command to add cross env in your Laravel project:
npm install cross-env --save-dev
Step 3: Remove "cross-env": "^5.1.1",
from package.json
Remove "cross-env":"^
from 5.1.1
",package.json
file devDependencies
section.
Step 4: Run npm
After updating your package.json
, run the following command to ensure that your project’s dependencies are up to date:
npm install
If you’re using Laravel Mix to build assets, you can run:
npm run dev
If you still find this error, setting PATH environment variable in Linux, macOS, and Windows allows you to specify directories where the system should look for executable files when you run commands in the terminal:
Setting the PATH in Windows:
- Set the PATH in each of these operating systems:
- Right-click on “This PC” or “My Computer” and select “Properties.”
- Click on “Advanced system settings.”
- Click the “Environment Variables” button.
- Under “System variables,” find “Path” (or “PATH”), select it, and click “Edit.”
- Click “New” and add the path to your directory.
Setting the PATH in Linux/Mac os:
- Set the PATH in each of these operating systems:
- To make the change permanent, you should modify your shell configuration file (e.g.,
~/.bashrc
,~/.bash_profile
, or~/.zshrc
for Bash or Zsh) by adding a line like this:- export PATH=/your/new/path:$PATH
- Use a text editor to open the file. For example, you can use
nano
:- nano ~/.bashrc
- Add the export line, save the file, and then run:
- source ~/.bashrc
- To make the change permanent, you should modify your shell configuration file (e.g.,
Conclusion
That’s it, you have learned how to fix cross env error in laravel applications.