webpack 使用出現的問題
照着教程寫的代碼,發現在項目根目錄運行 webpack 卻出現了問題
throw err; Error: Cannot find module ‘webpack/lib/node/NodeTemplatePlugin’
查了資料找到原因是全局安裝了webpack
解決方法是在本項目安裝 npm install webpack
於是就興高采烈地照着幹,結果
D:\nodejs\webpack>npm install webpack
npm ERR! Windows_NT 6.1.7601
npm ERR! argv D:\nodejs\node.exe”D:\nodejs\node_modules\npm\bin\npm-cl
i.js” “install” “webpack”
npm ERR! node v6.10.2
npm ERR! npm v3.10.10
npm ERR! code ENOSELF
npm ERR! Refusing to install webpack as a dependency of itself
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues
npm ERR! Please include the following file with any support request:
npm ERR! D:\nodejs\webpack\npm-debug.log
這就奇怪了,爲什麼?
又得繼續百度,
趕緊將package.json中的name字段清空。
完了繼續在根目錄執行 webpack ,結果OK了。