Skip to content

No builtin before builtin functions can break NVM when those functions are overwriten #3239

@Sargates

Description

@Sargates

I know the prompt said not to delete any parts. I don't care enough to fill it all out because the fix to this issue is so small

Operating system and version:

Windows 11, WSL Ubuntu, ZSH, NVM V0.39.5

How did you install nvm?

Install script

What steps did you perform?

See below

Is there anything in any of your profile files that modifies the PATH?

No

The issue and its fix is just to add the builtin keyword before each call of a builtin function.
In my case, I declared a function called hash in my .zshrc which overwrites the builtin hash function before nvm.sh gets sourced.
nvm.sh calls this new, overwritten hash function which may cause unintended behavior. I replaced the two calls of hash I could find in my build of nvm.sh with builtin hash instead and this fixed my issue.
This fix shouldn't break anything because it will always reference the intended hash function.

I know I could fix this by putting the lines

export NVM_DIR="$HOME/.nvm"
[ -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

before the part that sources all my custom .zsh files, but I found this issue and figured I would report it.

Side note:
I don't really use NVM or even Node, so I don't know what errors this specific case might cause.
What I did to cause this issue (overwriting the hash function) probably breaks some aspect of nvm so if someone does the same thing it might lead someone in the complete wrong direction of how to fix their issue.
The only reason I caught this was because of the way I implemented my hash function which caused there to be some output whenever I opened up a new terminal.

Metadata

Metadata

Assignees

Labels

shell alias clobberingAnything dealing with users shadowing builtins with aliases or functions.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions