Last active
September 1, 2026 00:12
-
-
Save nateware/7783571b9ccc7466deec7c425f827478 to your computer and use it in GitHub Desktop.
nvm lazy-loading trick - it is SO SLOW to load
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
| # Put this in ~/.zshrc (or ~/.bashrc) | |
| # nvm lazy-loading trick - it is SO SLOW to load | |
| # This will delay loading nvm until the first nvm/node/npm command | |
| export NVM_DIR="$HOME/.nvm" | |
| _nvm_lazy_load() { | |
| unset -f nvm node npm npx | |
| echo "Lazy loading nvm...\c" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
| [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |
| echo "done." | |
| "$@" | |
| } | |
| nvm() { | |
| _nvm_lazy_load nvm "$@" | |
| } | |
| node() { | |
| _nvm_lazy_load node "$@" | |
| } | |
| npm() { | |
| _nvm_lazy_load npm "$@" | |
| } | |
| npx() { | |
| _nvm_lazy_load npx "$@" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment