記一次vuepress報錯:UnhandledPromiseRejectionWarning: TypeError: res.getHeader is not a function


在使用vuepress時,按照官網的操作:

在執行完vuepress之后,控制台出現:

VuePress dev server listening at http://localhost:8080/

當將  http://localhost:8080/   放入瀏覽器並確定時,會出現以下報錯:

(node:8960) UnhandledPromiseRejectionWarning: TypeError: res.getHeader is not a function
    at processRequest (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\webpack-dev-middleware\lib\middleware.js:82:18)
    at ready (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\webpack-dev-middleware\lib\util.js:51:12)
    at handleRequest (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\webpack-dev-middleware\lib\util.js:167:5)
    at Promise (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\webpack-dev-middleware\lib\middleware.js:44:7)
    at new Promise (<anonymous>)
    at middleware (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\webpack-dev-middleware\lib\middleware.js:43:12)
    at Promise.all.Promise (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\koa-webpack\index.js:43:7)
    at new Promise (<anonymous>)
    at D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\koa-webpack\index.js:42:5
    at dispatch (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\koa\node_modules\koa-compose\index.js:42:32)
    at D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\@shellscape\koa-static\legacy\index.js:58:19
    at Generator.throw (<anonymous>)
    at step (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\@shellscape\koa-static\legacy\index.js:6:221)
    at _throw (D:\劉威\AmyProject\0326\vuepress-homepage\node_modules\@shellscape\koa-static\legacy\index.js:6:455)
(node:8960) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8960) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,
promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

在這個問題中,通過查找vuepress的issuse我知道是: webpack-dev-middleware 這個中間件的原因。

webpack-dev-middleware的作用就是:生成一個與webpack的compiler綁定的中間件,然后在express啟動的服務app中調用這個中間件。

個人推測(通過issuse里討論):因為webpack-dev-middleware的版本過高,造成了不兼容,所以每次啟動都會報這個錯

解決方法便是手動設置webpack-dev-middleware的版本:

npm install webpack-dev-middleware@3.6.0

設置成3.6.0版本,然后再一次加載全部依賴:

npm install

最后再次啟動項目即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM