0

I got this error when I do npm run dev , and I have installed the latest react/react-dom globally in my pc and locally in this project.

What can be done to fix this issue?

macbookpro@MacBookProdeMacBook-Pro 01.webpack-base % npm run dev

> 01.webpack-base@1.0.0 dev /Users/macbookpro/Desktop/01.webpack-base
> webpack-dev-server --open

internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Require stack:
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/cached-child-compiler.js
- /Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/index.js
- /Users/macbookpro/Desktop/01.webpack-base/webpack.config.js
- /usr/local/lib/node_modules/webpack-cli/bin/utils/convert-argv.js
- /usr/local/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js:14:28)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/child-compiler.js',
    '/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/lib/cached-child-compiler.js',
    '/Users/macbookpro/node_modules/_html-webpack-plugin@4.3.0@html-webpack-plugin/index.js',
    '/Users/macbookpro/Desktop/01.webpack-base/webpack.config.js',
    '/usr/local/lib/node_modules/webpack-cli/bin/utils/convert-argv.js',
    '/usr/local/lib/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! 01.webpack-base@1.0.0 dev: `webpack-dev-server --open`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the 01.webpack-base@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/macbookpro/.npm/_logs/2020-05-27T09_15_12_766Z-debug.log
zorandai
  • 1
  • 1
  • Does this answer your question? [Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'](https://stackoverflow.com/questions/43179531/error-cannot-find-module-webpack-lib-node-nodetemplateplugin) – Guilherme Abacherli Mar 30 '21 at 18:07

1 Answers1

0

I had a similar issue this bellow helped me to fix that

rm -rf node_modules
rm package-lock.json
npm cache verify
npm install

If it does not work maybe try this taken from Raunaqss's answer :

Webpack 4 onwards you are required to install webpack-cli. You may also want to install webpack-dev-middleware if you need to use the options marked with a key on this page.

In this case the command to install is:

npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware

As mentioned above, webpack-dev-middleware should be optionally added based on your requirements.

Shea Hunter Belsky
  • 2,815
  • 3
  • 22
  • 31
crg
  • 4,284
  • 2
  • 29
  • 57