Created
November 6, 2023 11:09
-
-
Save AshCoolman/ec3da0b1df7a30e38c9d4388cacb0436 to your computer and use it in GitHub Desktop.
Diagnose why yarn installed package returns "command not found" on CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ ! -f "package.json" ]; then | |
echo "No package.json. Run this at your project root." | |
exit 1 | |
fi | |
echo -n "Command not found: " | |
read command | |
if [ ! -d "./node_modules/.bin" ]; then | |
echo "Missing ./node_modules/.bin. Run 'yarn install'." | |
exit 1 | |
fi | |
if [ ! -f "./node_modules/.bin/$command" ]; then | |
echo "Missing command $command. Install with 'yarn add <package>'." | |
exit 1 | |
fi | |
if [[ ":$PATH:" != *":$(yarn global bin):"* ]]; then | |
echo "Yarn's bin not in PATH. Add with 'export PATH=\"$(yarn global bin):\$PATH\"' (probably use \$HOME) in .bashrc or .zshrc." | |
fi | |
if ! grep -q "\"$command\"" "package.json"; then | |
echo "Command $command not in scripts. Add it or run with 'yarn run <command>'." | |
fi | |
echo "Looks correct. Check package documentation or reinstall with 'yarn add <package>'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment