Cleaning up npm package install problems

Published: | Updated: | by Julian Knight Reading time ~2 min.
📖 Kb | 📎 Development | 🔖 Node-RED, npm, Node.JS, JavaScript, Debugging

Node-RED uses npm to manage package installations such as its nodes. Sometimes, you can get into a situation where you start getting lots of npm installation or removal issues and it feels like you are going round in circles trying to fix things. If so, time to call it a day and to get drastic! Here, I try to explain an easy way to fix things quickly and completely without side effects.

Node-RED is built over Node.js which uses npm as its library (AKA package) manager. It is great to have a standard mechanism to manage libraries but the complexities of managing JavaScript based packages sometimes trips things up.

Once you’ve tried for a bit to understand what the issues are, it may be time to call time and get drastic.

The following commmands will clean out the packages installed for your live instance of Node-RED - assuming you have it installed via the “standard” default method. If not, you will need to adjust the folder you operate in.

cd ~/.node-red
rm package-lock.json
rm -R node_modules
npm install

That will cleanly reinstall all of the packages marked in your package.json file. So make sure that is correct first. Every time you install a package (as long as you have reasonably up-to-date versions of Node.js and npm) whether from the NR admin ui or command line, it gets added to package.json.

I now always remove the lock file as well if I’m having issues as that can be the cause of some issues. The lock file isn’t generally needed in NR installations.

Note, as always, I’ve assumed you have a “standard” install of Node-RED which puts your userDir as ~/.node-red (and the equivalent on Windows). If you use an installation scheme like mine, it will be in a different place as noted by the command used to start NR.


comments powered by Disqus