NPM Hanging And Typescript Issues With Monterey OS

Exception Corner
Level Up Coding
Published in
2 min readMar 6, 2022

--

Photo by Natalie Chaney on Unsplash

Recently I’ve run into issues where NPM would refuse to install. It kept hanging, and blowing away node_module folder or clearing the NPM cache didn’t work. If you ever find yourself in this situation, here are some sure-fire ways to get you productive again.

NPM Hanging Issue

The first type of issue that lost me quite a bit of time resolving until I finally tried step 4 was due to a complex lerna project setup. No matter what I did, I lost the ability to install the application. To save you some time, here are some steps to try when you come across similar issues.

  1. First try blowing away your node_modules folder and re-install using npm ci.
  2. Clear the NPM cache using npm cache clean --force and re-install by following step 1.
  3. See if its related to your package-lock.json file by deleting it and running npm install.
  4. If none of these steps work, time for the nuclear option.
    On Mac, open finder, select Go Menu -> Go To Folder, type in ~/ to go to your home directory. Hit Cmd + Shift + . to show hidden files. Then delete .npmfolder.
    Windows users, I haven’t verified this but you should be able to clean up NPM by removing these folders C:\Users\YOUR_USER_NAME\AppData\Roaming\npm
    C:\Users\YOUR_USER_NAME\AppData\Roaming\\npm-cache

Monterey OS Typescript Issues

I recently had a colleague whose laptop updated to the latest OS and found themselves unable to be productive due to a random set of errors. Hopefully Apple or Node will address the root causes in the near future. Until then, here are some workarounds.

The first type of error is the Z_DATA_ERROR.

npm ERR! code Z_DATA_ERROR
npm ERR! errno -3
npm ERR! zlib: incorrect data check

If you start getting this, you’ll need to downgrade your version of node. As to what version that is, see this relevant post for more info.

https://stackoverflow.com/questions/69452504/zlib-error-when-attempting-to-run-npm-install-or-yarn

The second type of error is when you start to get a random typescript failure with your code.

The solution here was to bump down the version of typescript that was in use to v4.0.3. This eliminated the typescript issue.

In conclusion, I hope this article is of help to some of you. It would have saved me a couple of days of frustration had I known these tips upfront.

--

--