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

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

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

To resolve the error “cross-env is not recognized as an internal or external command, operable program or batch file in laravel”, you can try out the following steps:

  • Step 1: Delete node_modules Directory
  • Step 2: Reinstall cross-env
  • Step 3: Remove "cross-env": "^7.1.1", from package.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":"^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:

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:

  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:
      • nano ~/.bashrc
    • Add the export line, save the file, and then run:
      • source ~/.bashrc

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

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *