vuepress: vuepress dev: throws res.getHeader() is not a function
- I confirm that this is an issue rather than a question.
Bug report
- Related issue: https://github.com/webpack/webpack-dev-middleware/issues/380
- PR fix: https://github.com/shellscape/koa-webpack/pull/110
Version
- vuepress@0.14.10
- Reproduce same fault with node v10.9.0 AND node v8.11.4
- Windows 10
Steps to reproduce
NOTE: This was a first time use of vuepress.
$ npm i -g vuepress
$ echo "# Some Stuff" >> README.md
$ vuepress dev
> VuePress dev server listening at http://localhost:8080/
Visit http://localhost:8080/ in browser
Server throws …
(node:14508) UnhandledPromiseRejectionWarning: TypeError: res.getHeader is not a function
at processRequest (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\webpack-dev-middleware\lib\middleware.js:82:18)
at ready (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\webpack-dev-middleware\lib\util.js:51:12)
at handleRequest (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\webpack-dev-middleware\lib\util.js:167:5)
at Promise (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\webpack-dev-middleware\lib\middleware.js:44:7)
at new Promise (<anonymous>)
at middleware (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\webpack-dev-middleware\lib\middleware.js:43:12)
at Promise.all.Promise (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\koa-webpack\index.js:43:7)
at new Promise (<anonymous>)
at C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\koa-webpack\index.js:42:5
at dispatch (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\koa\node_modules\koa-compose\index.js:42:32)
at C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\@shellscape\koa-static\legacy\index.js:58:19
at Generator.throw (<anonymous>)
at step (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\@shellscape\koa-static\legacy\index.js:6:221)
at _throw (C:\ProgramData\nvm\v10.9.0\node_modules\vuepress\node_modules\@shellscape\koa-static\legacy\index.js:6:455)
(node:14508) 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:14508) [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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 63
- Comments: 60 (3 by maintainers)
Commits related to this issue
- Update package manifest Bumps the vuepress dependency to version 0.14.10 to fix the missing sidebar btton on a mobile homepage issue. This version introduces a bug when running the development server... — committed to rmjordas/awesome-vue by rmjordas 5 years ago
- SIM-1473 FIX downgrade of webpack. See https://github.com/vuejs/vuepress/issues/1417 — committed to Jsparrow/dashboard by deleted user 5 years ago
- Update package.json.ejs Fix res.getHeader is not function Ref: https://github.com/vuejs/vuepress/issues/1417 — committed to NamPNQ/vapid by NamPNQ 5 years ago
- feat: lock version of "webpack-dev-middleware" ref: https://github.com/vuejs/vuepress/issues/1417 https://github.com/webpack/webpack-dev-middleware/commit/b2a6fedce908bd348054b6fbb6e81fe638ef974... — committed to ulivz/koa-webpack by ulivz 5 years ago
- :pushpin: dependency: add resolutions NOTE: workaround of vuepress issue: https://github.com/vuejs/vuepress/issues/1417 — committed to kazupon/vue-i18n by kazupon 5 years ago
- 同步源仓库代码到本地仓库 (#4) * :pushpin: dependency: add resolutions NOTE: workaround of vuepress issue: https://github.com/vuejs/vuepress/issues/1417 * :package: build(vuepress): generate docs * :p... — committed to xuhongbo/vue-i18n by xuhongbo 5 years ago
- chore(pkg): fixing the vuepress getHeader issue. Read more at: https://github.com/vuejs/vuepress/issues/1417 — committed to machinelearnjs/machinelearnjs by JasonShin 5 years ago
- :pushpin: dependency: add resolutions NOTE: workaround of vuepress issue: https://github.com/vuejs/vuepress/issues/1417 — committed to etherdog-eth/vue-i18n by etherdog-eth 5 years ago
The dependency chain is
webpack-serve -> koa-webpack -> webpack-dev-middleware, and it’s caused by the underlyingwebpack-dev-middleware@3.6.1, so If you’re a yarn user you can useresolutionsfor a temporary fix:While the npm user can re-install
webpack-dev-middlewarewith a specific version:When
webpack-dev-middlewarefixes the issue and publishes, the issue can be closed.@edadams Sorry if my answer confused you, I didn’t have so much time at that point to dig down which dependency is the culprit.
Since @ulivz has found the exact module that caused the issue, you can override that module version in your
package.json, you can read more about the yarn’s resolution docs here, https://yarnpkg.com/lang/en/docs/selective-version-resolutions/What you want to do is to edit your
package.jsonfile, and add,And run
yarn installagain. Hope you got it fixed 😃the problem has been solved
npm i webpack-dev-middleware@3.6.0How to deal with the error
As a quick and temporary fix you can download 0.x yarn.lock and install dependencies from there.
Edit: @ulivz has a better solution. See below.
@bnb Based on previous answers, (you could read for more details)
Assuming you’re using yarn, add this to your
package.json,and
yarn installagain. Run viayarn docs:devoryarn docs:build.If you’re using npm, Run
npm install webpack-dev-middleware@3.6.0 --save-devin your local project folder. Add this to yourpackage.json,and run
npm run docs:devornpm run docs:build.These solutions will install a new local dependency of
webpack-dev-middleware@3.6.0, and before someone fixed the real root cause, you should be running with your package manageryarn docs:dev / npm run docs:dev, as this will use your local vuepress instead your global’s vuepress.So for those of you having issues still with the fixes listed above, a team mate of mine figured out that the issue was having Vuepress installed globally. It appears that the fixes above are only applying to your local project directory and is not being applied to the global installation.
Following these instructions, I was able to get it to finally work:
npm uninstall -g vuepressnpm install webpack-dev-middleware@3.6.0to install locally"vuepress:dev": "vuepress dev"to your package.json filenpm run vuepress:devYou may want to add the resolutions code from above to your package.json as well but I was able to get it to run without:
"resolutions": { "webpack-dev-middleware": "3.6.0" }I’m working at: 1、create package.json and don’t use global vuepress cli 2、install webpack-dev-middleware@3.6.0 in project 3、npm run docs:dev is working ex:
I tried to remove
node_modules,addwebpack-dev-middleware@3.6.0to mypackage.jsonand reinstall all dependencies with npm,but ended up with the same error.Then I turn to yarn and finally get it work.So for those who are still struggling with this error,it is strongly recommended to give yarn a tryCan a temporary solution for the globally installed VuePress be to published a version with a pinned
webpack-dev-middleware@3.6.0?I am using yarn, add this is my
package.jsonrunyarn installandyarn run docs:devIt work for meFixed at webpack/webpack-dev-middleware@56dc705 and released at
webpack-dev-middleware@v3.6.2.For now you can remove all of your hacking, just
rm -rf node_modulesand runnpm install / yarn.mac 10.13.6 npm install -D webpack-dev-middleware@3.6.0
why don’t use 1.x ? all these solutions I had tried but also made issues
采坑+1
解决方法: 删除 node_modules, 使用yarn 重新安装依赖。
你是全局安装的吗?我先删除了全局的vuepress,然后本地安装就可以正常运行了。
Adding the info below to package.json and using
yarn devsolved the issue for me.Thanks to @kucukkanat
Weird, that out of the box, it seemed to install v3.6.0 (I checked in the node_modules src for the package) but I still got the error.
I followed the
npm install -D webpack-dev-middleware@3.6.0advice which has now solved it.Just started my first VuePress and ran into the same
UnhandledPromiseRejectionWarning: TypeError: res.getHeader is not a functionerror. This is in a fresh project with nothing in it.Running
npm install -D webpack-dev-middleware@3.6.0like above fixed it for me (I’m using npm). I didn’t have to do anything else.Kinda strange to get this right out of the box… I’m sure it’ll be addressed soon.
Ah, that seems to be the difference – in your previous comment
--save-devwas omitted 👍Thanks, @abrahamdio. FWIW, it looks like the upstream fixes linked in the OP have already landed/been closed but the problem still seems to exist 😬
I can confirm that simply adding this to
package.json:and then reinstalling dependencies with
yarn installallowed it to work.Recommend actually reading this thread. There are several solutions.
On Mon, Mar 11, 2019 at 1:16 AM fanmucc notifications@github.com wrote: