Last updated: Apr 5, 2024
Reading timeยท2 min
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.
yarn install
You can also use the yarn
command to install all modules that are stored in
your package.json
file.
yarn
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:
{ "scripts": { "start": "react-scripts start" } }
If the command that starts your development server is named start
, then run
the yarn start
command.
yarn start
You can also install your modules and run the yarn start
command in a single
go.
yarn install && yarn start
If it is named dev
, then you would run yarn dev
.
yarn dev
If you need to build your project for deployment, the command will likely be
yarn build
.
yarn build
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.
# 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
.
# for macOS and Linux rm -rf node_modules # ๐๏ธ clean your yarn cache yarn cache clean # ๐๏ธ install packages yarn install
Try to start your development server after reinstalling your modules.
yarn start # OR if your script is named `dev` yarn dev
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:
#
, 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.