DEV Community

Discussion on: Using npx and npm scripts to Reduce the Burden of Developer Tools

Collapse
 
moopet profile image
Ben Sinclair

I think npx is a handy wrapper for giving a one-off demo in your project's README, but it quickly becomes a chore - at a talk the other day someone kept using it instead of installing the apps locally and it added about an extra 30 seconds to every single time they ran the build command. In other words, if you're going to use the command on the regular, don't use npx.

Collapse
 
bnb profile image
Tierney Cyren • Edited

I definitely agree that heavier CLIs may not be perfect. Specifically, I've noticed this problem with a lot of "modern" CLIs that have absolutely massive dependency trees to accomplish scaffolding tasks (think create-react-app).

That said, npm still caches the modules so after the first run (outside of situations like CI, where you should be using npm ci) this realistically shouldn't be a problem and now I'm super curious about why it was taking so long to run those commands 🤔

Collapse
 
moopet profile image
Ben Sinclair

I'm guessing that it was because the project was running BackstopJS (a visual regression testing tool) and in order to work cross platform, that runs in a docker container. If the npx command was running inside a container that didn't persist, then it would have to download everything every time.
TBH, I wasn't paying enough attention to that side of things to be able to give you an accurate description. I just assumed that it was npx that didn't cache anything!

Thread Thread
 
bnb profile image
Tierney Cyren

Ah yeah, a Docker container would have absolutely stripped any benefits there. In that case, you're 100% right that a normal global install would be best.

Ideally, pre-baking that into the image would be the best case scenario... but if they couldn't have done that taking Bryan Hughes advice from his comment on this post and putting it into devDependencies. Combining that with npm ci usage would be great too, since npm ci just reads the predetermined dependencies in the package-lock.json and doesn't take compute time to resolve the dependency structure.