webpack dev 日记

错误日志:

 1 \AppData\Roaming\npm\node_modules\webpack-cli\bin\cli.js:244
 2                                 throw err;
 3                                 ^
 4 
 5 Error: Cannot find module 'webpack/lib/RequestShortener'
 6     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
 7     at Function.Module._load (internal/modules/cjs/loader.js:497:25)
 8     at Module.require (internal/modules/cjs/loader.js:626:17)
 9     at require (C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack-cli\node_modules\v8-compile-cache\v8-compile-cache.js:159:20)
10     at Object.<anonymous> (D:\MyDisk\my-project\webpack\node_modules\uglifyjs-webpack-plugin\dist\index.js:19:25)

解决办法:

npm install webpack --save-dev

再次报错:

1 $ npm install webpack
2 npm ERR! code ENOSELF
3 npm ERR! Refusing to install package with name "webpack" under a package
4 npm ERR! also called "webpack". Did you name your project the same
5 npm ERR! as the dependency you're installing?
6 npm ERR!
7 npm ERR! For more information, see:
8 npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

原因是 package.json 文件中的 name 为 webpack,所以避免项目名称与插件名称重复