Temporary Fix to "Cannot Find Module" Error

During these trying times, I’ve had lots of projects that crash (basically every few hours), but remain in that crashed state and editing a file doesn’t trigger a re-install. In case it helps others, here’s what has been working for me:

If you keep getting errors like Error: Cannot find module 'module-name' even after you edit the files in your project (like package.json, or watch.json if you have one), then try opening the terminal, and then making an edit to a file (after the terminal has loaded).

My original approach of adding an invalid character to the package.json to trigger an parsing error (and thus a re-install) stopped working, but this new approach has served me well for the last day or so.

Of course, the challenge is often getting your project editor to load in the first place. My approach there is to just keep hitting the refresh button every few minutes.

Anyway, hope this helps those who have up-time-critical projects and are trying to survive this period of Glitch down-time.

Edit: Oh, or just type refresh in the terminal and hit enter once you’ve managed to get the terminal open… I forgot about that command.

Yes, refresh does work, and also, rebuilding the npm packages solved it for me. Edited the title to make it shorter.

3 Likes

rebuilding the npm packages solved it for me

Using the pnpm rebuild command? Is this better than running refresh, or just another thing that worked for you?

The pnpm package manager is having issues now. Use npm, it’s always worked for me without any issues.