Zsh command not found [Package]
For several reasons, including how you have installed nvm/npm, or issues with configuring the path, you may get the error zsh command not found for a certain package.
For the sake of this article, we will pick a random npm package, say ‘sequelize,’ and try to walk through the steps involved in debugging this type of error.
Install the Package
Because we are using sequelize in this example, the first step is to ensure you have sequelize installed.
npm i --save sequelize
Install Co-dependencies
Some packages have co-dependencies and may not work as expected if the co-dependencies are not installed. Sequelize, for example, needs the sequelize-cli to work well on your terminal.
npm i -g sequelize-cli
Add Appropriate Path Configurations
Add the path of the package installation to the .zshrc file. Path configurations allow your packages to be found in the right place when needed.
vi ~/zshrc
Check that you have the npm modules path in the file, depending on where your node modules are.
export PATH=/usr/local/share/npm/bin:$PATH
or
export PATH="$HOME/.npm-packages/bin:$PATH"
If none of these exist, and you still have this error, try this in the folder you want to work with:
node_modules/.bin/sequelize <sequelize command>For example:node_modules/.bin/sequelize model:generate --name HelpResources --attributes id:integer,link:string
If you have sequelize working in bash but not zsh, you can import all bash commands into sequelize like this:
source <bashrc path> ~/.zshrc
For example:
source /home/<your-username>/.bash_profile ~/.zshrcorsource ~/.bashrc ~/.zshrcorsource /Users/<your-username>/.bash_profile ~/.zshrc
Conclusion
Following the steps above should fix the issue with Zsh not recognizing the npm packages you have installed.