Why have to install webpack twice

I first install webpack global and I think it should work, but when to run webpack command at the project folder it throw error which said can’t find module webpack.

I read the guide of webpack it recommend to setup webpack as the project dependence. I can’t understand why has this design.

so many known issue I didn’t find a similar one so create this.

Author: Fantashit

2 thoughts on “Why have to install webpack twice

  1. You don’t have to install it globally.

    Local installation is better because every project could have a different webpack version.

  2. If you installed it globally then webpack ./entry.js bundle.js should work.
    Maybe you uninstalled it, and forgot? You can check like this:
    npm list --depth 0 --global webpack | grep webpack

    If you only have it installed locally, then you should execute:
    node_modules/.bin/webpack ./entry.js bundle.js from you project root. Or you could add it to your package.json scripts like this:

    "scripts" : {
      "build" : "webpack ./entry.js bundle.js"

    and execute: npm run build. This will still run the local version because npm will first look in ./node_modules/.bin/

    This is not so much a webpack issue as an npm feature. It’s just the way npm works.

    I hope I understood your question and answered it correctly.

Comments are closed.