Skip to content

Instantly share code, notes, and snippets.

@AshCoolman
Created November 6, 2023 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshCoolman/ec3da0b1df7a30e38c9d4388cacb0436 to your computer and use it in GitHub Desktop.
Save AshCoolman/ec3da0b1df7a30e38c9d4388cacb0436 to your computer and use it in GitHub Desktop.
Diagnose why yarn installed package returns "command not found" on CLI
#!/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