今天在使用html-webpack-plugin时只要一引用html-webpack-plugin就报错,报错信息类似下面这个样子:
module.js:471
throw err;
^
Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/htdocs/estate/node_modules/html-webpack-plugin/lib/compiler.js:11:26)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/htdocs/estate/node_modules/html-webpack-plugin/index.js:7:21)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)我使用的webpack2
重新安装html-webpack-plugin也搞不好,把我急死了,最后看看报错信息Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
这似乎是webpack包里面的一个东东,由于只是使用了webpack的命令行工具,所以我并没有本地安装webpack,那我本地安装一下webpack好了,我用的yarn:
$ yarn add webpack --save-dev结果还真的好了,我就奇怪了,包不是都会把依赖写进package.json中吗,既然html-webpack-plugin依赖了webpack,那么安装html-webpack-plugin就会自动把webpack安装好,为什么还要我来安一遍才好呢
再看看html-webpack-plugin的package.json,其中的devDependencies依赖的webpack版本是^1.14.0,我使用的webpack是2.x,所以可能是版本的问题吧,我猜,原因还在研究中...