Please stick with us in this article; you will find the cause of the lerna: command not found error and its solution. To resolve this problem, you will be instructed to install the Lerna package globally or use the ‘npx’ keyword at the beginning of each command.
Why does this error happen?
Suppose you want to create a new Lerna repository or upgrade an existing repository to the current version of Lerna. You run the ‘lerna init’ command and get the lerna: command not found error. You get this error message because you forgot the ‘npx’ prefix when running the commands or you don’t have your project’s Lerna package installed globally.
Solutions for the lerna: command not found error
The most accessible way to this problem is adding the ‘npx‘ keyword to the beginning of the commands before you run them. Here are some examples of command execution:
:: list all local packages npx lerna list :: import a package into the monorepo with the commit history npx lerna commit :: publish all packages in the current project npx lerna import
You can apply this method to any command in Lerna.
Alternatively, you can choose to install the Lerna package globally. To do that, run the install command with the ‘-g‘ flag as below:
npm install -g lerna
After executing the above command, you can check the version you have installed of Lerna:
If you also get the version of Lerna in the output, it means the installation was successful.
If the error still needs to be resolved after you have tried both of the above approaches. Let’s run this command:
npm config get prefix
This statement will return you a string. This string is the path to where the global packages are being located by ‘npm‘. You can find these packages in the bin directory of the specified path.
What you need to do is checking the PATH environment variable on the device you are using. If the PATH environment variable does not contain the return value of the ‘npm config get prefix’ command, set that value for it.
Note: If all methods are not working, let’s try uninstalling NodeJS on your machine and then reinstalling the latest version of NodeJS. To install the Lerna package globally, execute the command ‘npm install -g lerna’ again.
That’s the end of this post. To sum up, you can use the ‘npx’ prefix or install the Lerna package globally in your project to fix the lerna: command not found error. Hopefully, the information we mention below will help you.
Maybe you are interested:
- Create-next-app: command not found error
- Firebase: command not found error
- nx: command not found error
Name of the university: HUST