webpack打包报错:
[webpack-cli] Error: Cannot find module ‘webpack/lib/node/NodeTemplatePlugin’
错误提示:
[webpack-cli] Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Require stack:
- E:\Astudy\Athree\03_Webpack\mydemo\demo4\node_modules\_html-webpack-plugin@4.5.1@html-webpack-plugin\lib\child-compiler.js
- E:\Astudy\Athree\03_Webpack\mydemo\demo4\node_modules\_html-webpack-plugin@4.5.1@html-webpack-plugin\lib\cached-child-compiler.js
- E:\Astudy\Athree\03_Webpack\mydemo\demo4\node_modules\_html-webpack-plugin@4.5.1@html-webpack-plugin\index.js
- E:\Astudy\Athree\03_Webpack\mydemo\demo4\webpack.config.js
- E:\nodejs\node_global\node_modules\webpack-cli\lib\webpack-cli.js
- E:\nodejs\node_global\node_modules\webpack-cli\lib\bootstrap.js
- E:\nodejs\node_global\node_modules\webpack-cli\bin\cli.js
- E:\nodejs\node_global\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (E:\nodejs\node_global\node_modules\webpack-cli\node_modules\_v8-compile-cache@2.2.0@v8-compile-cache\v8-compile-cache.js:159:20)
at Object.<anonymous> (E:\Astudy\Athree\03_Webpack\mydemo\demo4\node_modules\_html-webpack-plugin@4.5.1@html-webpack-plugin\lib\child-compiler.js:14:28)
at Module._compile (E:\nodejs\node_global\node_modules\webpack-cli\node_modules\_v8-compile-cache@2.2.0@v8-compile-cache\v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'E:\\Astudy\\Athree\\03_Webpack\\mydemo\\demo4\\node_modules\\_html-webpack-plugin@4.5.1@html-webpack-plugin\\lib\\child-compiler.js',
r.js',
'E:\\Astudy\\Athree\\03_Webpack\\mydemo\\demo4\\webpack.config.js',
'E:\\nodejs\\node_global\\node_modules\\webpack-cli\\lib\\webpack-cli.js',
'E:\\nodejs\\node_global\\node_modules\\webpack-cli\\lib\\bootstrap.js',
'E:\\nodejs\\node_global\\node_modules\\webpack-cli\\bin\\cli.js',
'E:\\nodejs\\node_global\\node_modules\\webpack\\bin\\webpack.js'
]
}
解决办法:
执行命令 npm link webpack --save-dev
然后再执行webpack
就可以了