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

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":"^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

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:

  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

That’s it, you have learned how to fix cross env error in laravel applications.

Recommended Tutorials

AuthorDevendra Dode

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 *