Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' at Function.Module._resolveFilen

Error: Cannot find module ‘webpack/lib/node/NodeTemplatePlugin’
at Function.Module._resolveFilename (module.js:489:15)
at Function.Module._load (module.js:439:25)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object. (D:\webpack\node_modules\html-webpack-plugin\lib\compiler.js:11:26)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Module.require (module.js:517:17)
at require (internal/module.js:11:18)
at Object. (D:\webpack\node_modules\html-webpack-plugin\index.js:7:21)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] webpack: webpack --config webpack.config.js --progress --colors --display-modules
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] webpack 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! C:\Users\wangxueting\AppData\Roaming\npm-cache_logs\2017-08-18T03_09_11_308Z-debug.log

解决方法及原因:

造成次问题的原因是全局安装了webpack,把全局的清除掉
npm uninstall -g webpack

在本地项目下安装webpack
npm install webpack
如果已经在本项目下安装了webpack,执行npm install webpack会报错,不用理会。
报错如下:(表示已经安装了webpack了)
npm ERR! path D:\webpack\node_modules\fsevents\node_modules\dashdash\node_modules
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall lstat
npm ERR! Error: EPERM: operation not permitted, lstat 'D:\webpack\node_modules\fsevents\node_modules\dashdash\node_modules'
npm ERR! { Error: EPERM: operation not permitted, lstat 'D:\webpack\node_modules\fsevents\node_modules\dashdash\node_modules'
npm ERR! stack: 'Error: EPERM: operation not permitted, lstat \'D:\\webpack\\node_modules\\fsevents\\node_modules\\dashdash\\node_modules\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'lstat',
npm ERR! path: 'D:\\webpack\\node_modules\\fsevents\\node_modules\\dashdash\\node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\wangxueting\AppData\Roaming\npm-cache\_logs\2017-08-18T03_16_48_094Z-debug.log

你可能感兴趣的:(webpack)