Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does npx install webpack every time?

Tags:

I have a JavaScript app I'm bundling with webpack. Per the docs, I'm using this command to start bundling:

npx webpack

Each time I get this output:

npx: installed 1 in 2.775s

I've verified that the webpack command exists in my ./node_modules/.bin directory where npx is looking. Can anyone think of why it's downloading webpack every time? It can take up to 7 seconds to complete this step, which is slowing down my builds.

like image 986
serverpunk Avatar asked Mar 15 '18 14:03

serverpunk


People also ask

Is NPX automatically installed?

Calling npx <command> when <command> isn't already in your $PATH will automatically install a package with that name from the npm registry for you, and invoke it.

Does NPX install the package?

Npm is a tool that use to install packages. Npx is a tool that use to execute packages. Packages used by npm are installed globally. You have to care about pollution in the long term.

Is NPX better than npm?

If the package in question is to be used only once or twice and not every time the project runs, it is better to use NPX because it would execute the package directly, without installing it. NPM is used to install packages, and we should do this in case of dependencies or packages which are crucial to our project.

Does NPX install locally or globally?

npx is a replacement for installing global packages. It encourages you to install packages locally, but still be able run them as if they were global, just with npx .


1 Answers

npx doesn't reuse previously installed packages, instead it pulls down that package's dependencies every time that you run it.

like image 163
Maksim Shamihulau Avatar answered Oct 21 '22 18:10

Maksim Shamihulau