How can I optimize the npm installation process?

I’m managing an older project that runs on Node.js 16 and uses workspaces to compile its various artifacts. Lately, I’ve noticed that the npm installation process is taking over three minutes, which is slowing down our entire build pipeline. I experimented with alternative package managers like pnpm and yarn, but they both encounter errors when building certain artifacts from our legacy repository, making debugging a headache. Does anyone have practical suggestions or proven methods to significantly reduce the npm install time?

Working on a similar older project, I found that cleaning up redundant dependencies and ensuring the package-lock file is up-to-date made quite a difference. For me, switching from npm install to npm ci not only reduced the installation time but also improved consistency across builds. In our CI workflow, caching the node_modules folder between builds proved effective despite the potential pitfalls. Sometimes addressing deeper issues like overlapping dependencies in workspaces led to improvements in installation speed that are hard to achieve by tweaking npm flags alone.