运行webpack后出现此错误。Webpack已全局安装,并且我正在运行Node
PS D:\Projects\ng2-admin-master> ng serve Cannot find module 'webpack/lib/node/NodeTemplatePlugin' 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> (D:\Projects\ng2-admin-master\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> (D:\Projects\ng2-admin-master\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) PS D:\Projects\ng2-admin-master>
Node需要您将webpack安装到您的项目中。
您可以通过以下两种方法解决上述问题:
npm uninstall -g webpack npm install --save-dev html-webpack-plugin webpack webpack-dev-server
npm i webpack -g; npm link webpack --save-dev
您可以根据需要省略html-webpack-plugin。
您可以在此github问题页面上找到更多信息。
更新(2018年4月)
从Webpack 4开始,您需要安装webpack-cli。webpack-dev- middleware如果需要使用此页面上标有键的选项,则可能还需要安装。
webpack-cli
webpack-dev- middleware
在这种情况下,要安装的命令是:
npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev- server webpack-dev-middleware。
npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev- server webpack-dev-middleware
如上所述,webpack-dev-middleware应根据您的要求选择添加。
webpack-dev-middleware