可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Getting error when running webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/
. Here is the error log:
module.js:442 throw err; ^ Error: Cannot find module 'webpack/bin/config-yargs' at Function.Module._resolveFilename (module.js:440:15) at Function.Module._load (module.js:388:25) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3)
回答1:
I've had a similar problem. I think it's related to webpack version. After changing webpack version the latest everything was fine...
回答2:
Try changing the webpack version from 1.x to 2.x in your package.json:
Eg:
"devDependencies": { "webpack": "2.2.0-rc.3", "webpack-dev-server": "2.1.0-beta.0", "webpack-validator": "^2.3.0" }
This happens sometimes when you use pre-release version of webpack-dev-server
with released version of webpack
or viceversa.
回答3:
I also go this error when I had only installed webpack
locally and hadn't installed it globally yet.
I had webpack-dev-server
installed globally though and it had a dependency on a global install of webpack
. To be fair npm did complain while installing webpack-dev-server
:
UNMET PEER DEPENDENCY webpack@^2.2.0
回答4:
I fixed this solution by running npm start
which was just a wrapper running 'webpack-dev-server' rather than running webpack-dev-server
directly into the console. The problem was that I was passing options into a method I should not have been passing options into.
Running webpack-dev-server
with npm start
showed me the correct error message. Running webpack-dev-server
directly only gave me "Error: Cannot find module 'webpack/bin/config-yargs' ". Weird.
I am on: "webpack": "^2.6.1", "webpack-dev-server": "^2.7.1"
回答5:
The general situation is due to Webpack and webpack-dev-server version is not compatible. Like I also have this problem, my computer's webpack is 1.15.0, but webpack-dev-server is 2.x above version. So I uninstall webpack-dev-server: npm uninstall webpack-dev-server -g Then install the 1.15.0 version of webpack-dev-server, you can solve this problem by npm install webpack-dev-server@1.15.0 -g
回答6:
This is usually due to version mismatches between libraries (including webpack/yargs, in your case). This can happen a lot when you have left a project sitting for a while and some dependencies in your node_modules directory have become stale. A very simple solution, before fussing with different versions of everything, is to just move your node_modules directory to a temporary location and re-run npm install:
% mv node_modules nod_modules.REMOVED % npm install
Then, try rerunning webpack.
回答7:
Try changing webpack version to 3.0 and web-dev-server to 2.7.1
Eg:
"devDependencies": { "webpack": "^3.0.0", "webpack-cli": "2.0.13", "webpack-config-utils": "2.0.0", "webpack-dev-server": "^2.7.1", "webpack-validator": "2.2.7" }