When you face the 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 configuration of your project. This error is related to the cross-env package, which is used to set environment variables in a cross-platform way.
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.
‘cross-env’ is not recognized as an internal or external command Laravel
Steps to fix laravel ‘cross-env’ is not recognized as an internal or external command error:
- Step 1: Delete node_modules Directory
- Step 2: Reinstall cross-env
- Step 3: Remove
"cross-env": "^7.1.1",
frompackage.json
- Step 4: Run npm
Step 1: Delete node_modules Directory
Firstly, open your cmd or terminal and execute 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
If cross-env is not installed in your project, you need to add it as a development dependency. Run the following command in your Laravel project directory:
npm install cross-env --save-dev
Step 3: Remove "cross-env": "^5.1.1",
from package.json
Next, you need to 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
Still found this error, you can Setting the 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. Here’s how to set the PATH in each of these operating systems:
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
: - Add the export line, save the file, and then run:
- To make the change permanent, you should modify your shell configuration file (e.g.,
Conclusion
By following these steps, you should be able to resolve the “‘cross-env’ is not recognized as an internal or external command” error in your Laravel project. It’s important to ensure that ‘cross-env’ is correctly installed, specified in your scripts, and that your environment variables and PATH are properly configured.