Last active
September 6, 2017 17:08
-
-
Save classmember/0412182608b2dc4588e8790a2add97ee to your computer and use it in GitHub Desktop.
npm test "Error: Cannot find module" solution - this shell script installs all missing npm packages
This file contains 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/sh | |
# npm test wouldn't run due to missing or unresolved packages. | |
# This script installs all missing packages from error messages. | |
# Fix missing packages | |
missing_package="$( | |
npm test 2>&1 | | |
grep 'Cannot find module' | | |
cut -d\' -f2)" | |
while [ -n "${missing_package}" ] ; do # while missing packages | |
echo "[+] installing ${missing_package}" # report what is installing | |
npm install "${missing_package}" # install the package | |
missing_package="$( # update missing_package for loop | |
npm test 2>&1 | | |
grep 'Cannot find module' | | |
cut -d\' -f2)" | |
done | |
# Fix unresolved packages | |
missing_package="$( | |
npm test 2>&1 | | |
grep "Can't resolve" | | |
cut -d\' -f3)" | |
while [ -n "${missing_package}" ] ; do # while missing packages | |
echo "[+] installing ${missing_package}" # report what is installing | |
npm install "${missing_package}" # install the package | |
missing_package="$( # update missing_package for loop | |
npm test 2>&1 | | |
grep "Can't resolve" | | |
cut -d\' -f3)" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment