Yarn error: Command failed with exit code 127 [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
2 min

banner

# Yarn error: Command failed with exit code 127 [Solved]

The yarn error "Command failed with exit code 127" most commonly occurs when you forget to install the modules before running your yarn commands.

To solve the error, run the yarn install command before running yarn start.

Open your terminal in your project's root directory (where your package.json file is) and run the following command.

shell
yarn install

run yarn install command

You can also use the yarn command to install all modules that are stored in your package.json file.

shell
yarn

run yarn install command

Try to start your development server after running yarn install.

You can view your start command in the scripts section of your package.json file.

It might look similar to the following:

package.json
{ "scripts": { "start": "react-scripts start" } }

If the command that starts your development server is named start, then run the yarn start command.

shell
yarn start

You can also install your modules and run the yarn start command in a single go.

shell
yarn install && yarn start

If it is named dev, then you would run yarn dev.

shell
yarn dev

If you need to build your project for deployment, the command will likely be yarn build.

shell
yarn build

# Delete node_modules and rerun yarn install

If the error persists, delete your node_modules directory and rerun yarn install.

Open your terminal in your project's root directory (where your package.json file is).

If you are on Windows, run the following commands in CMD.

cmd
# for Windows rd /s /q "node_modules" # ๐Ÿ‘‡๏ธ clean your yarn cache yarn cache clean # ๐Ÿ‘‡๏ธ install packages yarn install

If you are on macOS or Linux, run the following commands in bash or zsh.

shell
# for macOS and Linux rm -rf node_modules # ๐Ÿ‘‡๏ธ clean your yarn cache yarn cache clean # ๐Ÿ‘‡๏ธ install packages yarn install

yarn cache clean

Try to start your development server after reinstalling your modules.

shell
yarn start # OR if your script is named `dev` yarn dev

# Make sure the folders in your project's path don't contain spaces or special characters

Another common cause of the error is when the folders in your project's path contain spaces or special characters.

Make sure none of the folders in your project's path contain:

  • spaces.
  • hash symbols #, colons :, dollar signs $, etc.

The issue is caused if any of the folders in the path contain spaces or special characters, not just your root project folder.

I've also written an article on how to force yarn to reinstall a package.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev