webpack热更新无效解决,页面无刷新

问题:控制台输出, 但页面内容并没有进行热加载

[WDS] App updated. Recompiling...
[WDS] App hot update...
...

报错: 

Error: Cannot find module 'webpack-cli/bin/config-yargs'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object. (E:\webpack\node_modules\[email protected]@webpack-dev-server\bin\webpack-dev-server.js:84:1)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2019-02-15T13_59_30_515Z-debug.log

解决:这种情况下一般是webpack版本与webpack-dev-server版本不兼容的问题, 这个时候我们不仅需要检查开发环境所需的webpack版本号与webpack-dev-server号,还要检查生产环境的webpack-dev-server是否一致,不一致则改为一致。

// 查看webpack-dev-server是否一致 

"devDependencies": {
    ...
    "webpack": "^3.11.0",
    "webpack-dev-server": "^2.11.1",
    ...
  },
  "dependencies": {
    ...
    "webpack-dev-server": "^2.11.1",
    ...
  }

到此,可以把项目跑起来,实现热更新。

你可能感兴趣的:(webpack热更新无效解决,页面无刷新)