1 thought on “Error: Cannot find module ‘webpack/lib/node/NodeTemplatePlugin’

Comments are closed.

18 thoughts on “Error: Cannot find module ‘webpack/lib/node/NodeTemplatePlugin’

  1. I got this same error, reinstalled it locally and ran it with package scripts and it worked.

    • npm remove webpack -g
    • npm i webpack --save-dev
      "name": "reactjsprogram",
      "version": "1.0.0",
      "description": "http://courses.reactjsprogram.com/courses/reactjsfundamentals",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "webpack": "npx webpack",
        "watch": "npx webpack -w",
        "clean": "rm -r ./dist/"
      "repository": {
        "type": "git",
        "url": "git+https://github.com/natsn/reactjsprogram.git"
      "author": "",
      "license": "ISC",
      "bugs": {
        "url": "https://github.com/natsn/reactjsprogram/issues"
      "homepage": "https://github.com/natsn/reactjsprogram#readme",
      "devDependencies": {
        "coffee-loader": "^0.7.2",
        "coffee-script": "^1.10.0",
        "html-webpack-plugin": "^2.9.0",
        "webpack": "^1.12.14"

    … then npm run webpack

  2. Hey natsn! I removed it globally and installed local. Run npm run webpack and I believe it executed successfully. Now, whe I just run webpack by itself, it says: -bash: /usr/local/bin/webpack: No such file or directory. So, to make it run: ./node_modules/.bin/webpack -w

  3. install it globally if you want the CLI anywhere. ever install it locally in your project if you use webpack. the global CLI will use the locally installed version when installed.

  4. @timotius02 I was unclear about this for a while as well. In the course chapter you’re on, it’s true that you should install it locally to make it appear in node_modules folder in order for you to actually run webpack in your command line for it to work right. I followed his instruction to install it globally and ran into the same problem and error as you did at the same time. Thus, I am telling him he should update his instructions to include the need to install it both globally and locally for different reasons.

    My confusion was cleared up when I realized the chapters with text are purely meant to be digested and he walks us through the actual process to follow along in the video sections! I was so confused until this was pointed out to me!

  5. @pwang2 I know npm i webpack --save-dev solves the issue, but would you like to share why saving it to dev dependencies is working and npm i -g webpack is not?

  6. @lawrence1223 , as @sokra–author of webpack mentioned here, this is how npm and node require are supposed to work, the global install package are not available as your projects’ dependencies require. A global install will probably add some CLI to your $PATH but by default the module itself will not be exported as documented here.

  7. No need to install it locally, just link the globally installed package to your project. This will make updates far simpler.
    npm i webpack -g; npm link webpack –save-dev

  8. I tried for hours almost every thing suggested on different threads on Stack overflow but nothing worked. Eventually (with a lot of luck) I tried this and it worked:

    deleted node_modules library (not sure if required)
    npm install -g @angular/cli
    npm install @angular/cli
    npm install
  9. I was getting this error after I tried to install moment, which threw some exceptions and could not get installed properly.

    The issue got fixed after I deleted node_modules folder and ran “npm install”

Comments are closed.