DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Avoid npm build errors by tracking your Node version with nvm
Chris Colborne
Chris Colborne

Posted on • Originally published at chriscolborne.com on

Avoid npm build errors by tracking your Node version with nvm

You know the feeling. You get a spare moment jump in and do some updates on an old app. But you try to get it running and the dreaded npm errors come up.

Oftentimes, the issue is that youโ€™ve updated Node since you last ran it. Many issues with dependencies and npm can been easily solved by switching Node versions.

Easy, so just go back to the version of node you used when you originally developed it. But how do you know which version to jump to? Just guess and check?

Perhaps you can leave a note in your README saying โ€œThis works in Node version X.โ€ And sure, thatโ€™s certainly one way of solving it.

But using nvm, we can track the version, as well as automate the switch back, and thatโ€™s what weโ€™ll talk about today.

nvm is Node Version Manager. It primarily allows you to switch between isolated Node environments for different versions. If youโ€™ve used rvm/rbenv in Ruby, itโ€™s similar to that.

For our purposes today however, the killer feature is the .nvmrc file. .nvmrc is a file you commit with your project which contains a single line with the version of Node to use for this project.

In a project with an .nvmrc file, you can type nvm use and it will automatically switch back to the version youโ€™ve stated. If youโ€™re really keen, you can (and Iโ€™d say you should) also set up your shell to automatically nvm use when it encounters an .nvmrc file.

So start using nvm and .nvmrc in your projects and next time youโ€™re returning to an old project, youโ€™re just an nvm use away from being back up and running quick smart.

Top comments (2)

Collapse
 
liloxjah profile image
Info Comment hidden by post author - thread only accessible via permalink
Kwadwo Annie

@zorfling please i need assistance from you

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more

๐ŸŒš Browsing with dark mode makes you a better developer.

It's a scientific fact.