Laravel ‘cross-env’ is not recognized as an internal or external command

[ad_1]

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.

Ezoic

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", from package.jsonEzoic
  • 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:

Ezoic

# 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:

Ezoic

npm install cross-env --save-dev

Step 3: Remove "cross-env": "^5.1.1", from package.json

Next, you need to remove "cross-env":"^5.1.1", from 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:

Ezoic

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:

Ezoic

Setting the PATH in Windows:

  1. 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:

  1. 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:

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.

Recommended Tutorials

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00