We've been getting reports of strange errors after at npm that seem to only have the use of the n node version manager in common.
Looking through the source, I _think_ n copies the new version into place without removing the existing one? That is: https://github.com/tj/n/blob/master/bin/n#L490
If so, then these errors are not too surprising. Copying without removing the existing copy means that switching from an older npm with deeply nested dependencies to a newer one that's flattened them will result in npm loading the wrong version of its associated libraries.
You didn't run into this problem before because historically, npm always shipped an entirely unflattened, npm@2-style, tree. This was necessary due to bugs in the officially Node.js installer that was resolved earlier this year. With that resolved, we were able to flatten the tree, fixing path length-limits for windows and substantially reduce the distribution size.
You can see this for yourself with:
$ n 8
...
$ n latest
...
$ npm install @iarna/emojitime
npm ERR! asyncWrite is not a function
npm ERR! pna.nextTick is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /home/rebecca/.npm/_logs/2018-06-08T20_11_55_504Z-debug.log
(Doesn't need to be @iarna/emojtime, any package that's not in your cache will trigger the crash.)
You can demonstrate that this is a bug in the version activation step, because the following _won't_ error:
$ $(dirname $(n bin 10.4.0))/npm i @iarna/emojitime
(But do remember that after you've successfully installed a version, it will no longer error, so to go back to reproing the problem you'll need to either npm cache clean --force or use a different package.)
I've been trying to find the best way to solve this issue. Because node ships with npm whatever version you would switch to, it would bring the version of npm that you need. The flatten dependency thing puts a major issue with the old functionality. I don't wanna create a fix that will break the old versions of how it would handle npm. Because this is node version manager, I don't want the absence of npm to not be coupled with the versions that ship it with node. I'll look into PR #470 to see if that will resolve the issue.
Closing issue and publishing a new version 2.1.12 from PR #470 to fix issue listed above.
@troy0820 switching version still seems to switch the npm version to a previous version as well. Is there a way to stop it overriding your existing version? Particularly it's the audit feature I feel I'm missing when it swaps my version - found a lot of vulnerabilities I was unaware of because I hadn't been seeing that vulnerability output, didn't realize I was getting put back to an outdated version of npm.
Most helpful comment
Closing issue and publishing a new version
2.1.12from PR #470 to fix issue listed above.