When developing software for Node.js, I use the n package manager to manage and switch between Node versions. Recently, I needed to update my installed Node version (9.2.1) to something more recent. I ran
$ sudo n latest to install 13.1.0. But after the upgrade, npm installations stopped working. Any use of
npm i would error with:
ERR! Cannot read property 'resolve' of undefined
After extensive research, it turned out this was the result of an incompatibility between old versions of n (<2.1.12) and recent versions of node.
Online forums said the solution was to downgrade back to the older version of Node and be happy with that. I needed the newer Node, so this wasn’t an option. But there was a catch-22: in order to update n to a later version compatible with recent Node, I needed to use npm, which n had broken.
Here are the steps I tried that ended up working.