I have come to using a multi stage Docker build. One to install dependencies and build whatever it is. I then might have a second clean docker image where the dependencies are copied to and run.
This helps with localized risk, and some production risk - but not all of it.
NPM packages have become a huge nuisance security wise.