devnull.land

Miscellaneous bits and bobs from the tech world

Got some npm or yarn errors and can't install dependencies anymore?

9/22/2021, 8:32:13 PM


There are few things more disheartening than when you are in the middle of a task, you run npm install or yarn, and everything goes to pieces – your working directory's node_modules/ are fubar'd, and no amount of running npm install or yarn will make it go away.

Maybe your error looks something like this:

node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: EISDIR: illegal operation on a directory, read
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -21,
  code: 'EISDIR',
  syscall: 'read'
}

In my case, I had been running an npm install command when the process was killed (it was being run as part of a test suite and the test timed out, thus killing the process). It left node_modules/ in a usable state, so I didn't even think this was the cause when the next time I ran yarn, and things went sideways quickly.

Keep calm™, and do the following, trying yarn or npm again in between to see if it fixes

  1. rm yarn.lock or rm package-lock.json
  2. yarn cache clean or npm cache clean
  3. Delete your node_modules/ and start fresh
  4. Nuke your local checkout from orbit, have a coffee, and git clone again

Hopefully one of the above steps will get you going again.

Happy hacking!