This error is pretty annoying, and well, installing packages with Node is always a somewhat a bumpy experience. In some cases it might work, but most of the time, like I said, it isn’t the smoothest of experiences. The error mainly occurs if you’re trying to install something globally, otherwise, it can happen, but it is pretty rare. The fix for this is actually unbelievably simple.
Fix “Cannot Find Module” Error – Global Install Not Working
The following fix will be for Windows users only. Open up the Start Menu, and then type in “Path”. When “Edit the system environment variables” presents itself, click it.
After that, click on Environment Variables which is on the Advanced tab.
Here, you’ll need to setup a NODE_PATH. If you have one previously setup it will be in the list. The first list is for variables for the current account, and the one on the bottom is for shared variables or system variables.
You’ll need to create a NODE_PATH in either or. If you don’t have one in the list, do the following:
- Click on “New”.
- At variable name, type in: “NODE_PATH” – without double quotation marks, of course.
- As for the variable value, type in the following path: C:\Users\YOUR USER\AppData\Roaming\npm\node_modules
- Hit OK, and close out of the other windows as well.
If you have a NODE_PATH already setup, I suggest switching it to the path from above, as it is the simplest location for node modules, and it does seem to work properly every time.
To modify a NODE_PATH, simply highlight it, and hit “Edit”. Then, just change the variable value, and the name if needed and hit OK. You can then close out of the other windows as well.
At the moment it does seem like the “Cannot find module” error is usually caused by not having a proper node path. I’m sure the same fix can be applied to Linux systems as well, but the methodology will vary quite a lot.