Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this._implicitHeader is not a function #2754

Closed
738623786 opened this issue Mar 29, 2021 · 17 comments · Fixed by #6313 or #6557
Closed

this._implicitHeader is not a function #2754

738623786 opened this issue Mar 29, 2021 · 17 comments · Fixed by #6313 or #6557
Labels
bug: upstream Bug in a dependency of Vite

Comments

@738623786
Copy link

738623786 commented Mar 29, 2021

Visit "http://localhost:5000" after running "npm run serve",I get the following error:
xxx\node_modules\vite\dist\node\cli.js:13753
this._implicitHeader();
^

TypeError: this._implicitHeader is not a function
at Http2ServerResponse.end (xxx\node_modules\vite\dist\node\cli.js:13753:14)
at Array.write (xxx\node_modules\vite\dist\node\chunks\dep-0776dd57.js:49039:9)
at listener (xxx\node_modules\vite\dist\node\chunks\dep-0776dd57.js:48312:15)
at onFinish (xxx\node_modules\vite\dist\node\chunks\dep-0776dd57.js:48243:5)
at callback (xxx\node_modules\vite\dist\node\chunks\dep-0776dd57.js:48104:10)
at Http2ServerRequest.onevent (xxx\node_modules\vite\dist\node\chunks\dep-0776dd57.js:48142:5)
at Http2ServerRequest.emit (events.js:315:20)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

@github-actions
Copy link

Hello @738623786. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by need reproduction will be closed if no activities in 3 days.

@Shinigami92
Copy link
Member

@738623786 Please respect our Issue Template
Please open a new issue and use the Issue Template

@gunters63
Copy link

gunters63 commented Mar 31, 2021

I have the same issue and found the reason.

The culprit is the compression module for express which does not support http2:

Support for Node.js 8 native http2

The preview module of vite serve does use compress.

When I start chrome with the parameter --disable-http2 the error goes away.

I guess reproduction of this error needs a combination of a recent Chrome browser and Node . I use Chrome 89 and Node 14 LTS.

@gunters63
Copy link

I patched vite locally in my node_modules folder according to the following commit which unfortunately was never merged into compress:

[Fix usage of undocumented _implicitHeader and _header]
(expressjs/compression@dbf7e73)

This fixed the error

@patak-dev
Copy link
Member

Great finding @gunters63! Maybe you could do a PR to expressjs/compression showing this use case, it would be great if this was fixed. I'll reopen this issue with a bug:upstream label to track this.

@patak-dev patak-dev reopened this Mar 31, 2021
@patak-dev patak-dev added bug: upstream Bug in a dependency of Vite and removed needs reproduction labels Mar 31, 2021
@gunters63
Copy link

gunters63 commented Mar 31, 2021

Issue 122 is already unresolved now for 4 years.

If I understand correctly, there are still some hard to solve stability problems regarding compress and HTTP/2 which is why the proposed fix was never merged. So I don't think it makes sense to send a PR request to the compression maintainers.

I would suggest making the use of compress in vites server cli configurable, something like:

  if (config.server.compress) {
    app.use(compression())
  }

@gunters63
Copy link

I wrote a comment now in the corresponding issue of compression.

@gunters63
Copy link

I also replaced vite preview now with sirv-cli (see comment of Greenheart)

@hanneswidrig
Copy link

Hey I'm having this issue with a basic templated vite project, is there ever going to be a solution to this? When exactly does vite preview actually work?

@jozefizso
Copy link

vite preview fails with node v14.18.1 and v16.13.0 when we enable the https server option.

/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:91827
        this._implicitHeader();
             ^

TypeError: this._implicitHeader is not a function
    at Http2ServerResponse.end (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:91827:14)
    at Array.write (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:45268:9)
    at listener (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:44541:15)
    at onFinish (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:44472:5)
    at callback (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:44333:10)
    at Http2ServerRequest.onevent (/home/jozef/outlook/node_modules/vite/dist/node/chunks/dep-85dbaaa7.js:44371:5)
    at Http2ServerRequest.emit (events.js:400:28)
    at endReadableNT (internal/streams/readable.js:1334:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
error Command failed with exit code 1.

When we disable the HTTPS this error does not happen.

@Moshyfawn
Copy link

Using Node 16.12.0 here. I've encountered this behavior:
Running vite preview results in TypeError: this._implicitHeader is not a function once the URL is reached in browsers like Safari 15.1, Chromium 95.0.4638.54. In Firefox 95.0b6, it fails if Private Browsing is used. It proceeds to serve the files otherwise.

@Niputi
Copy link
Contributor

Niputi commented Dec 14, 2021

would be nice if someone could provide a full reproduction in gtihub repo with os/browser details.
I might have a fix for this but would need to be able reproduce error to know If I can fix it

@Moshyfawn
Copy link

Moshyfawn commented Dec 15, 2021

would be nice if someone could provide a full reproduction in gtihub repo with os/browser details. I might have a fix for this but would need to be able reproduce error to know If I can fix it

Here's a StackBlitz sandbox (requires browser's WebContainer support) that's connected to a GH repo

  1. Install deps
  2. Run build cmd
  3. Run preview cmd
  4. Open https://localhost:5000

You might encounter some issues running preview cmd in StackBlitz, so it's better to do it on a local machine instead.

My experience, can reproduce in any browser other than Firefox every time 100% on Windows 11 & MacOS 12.0.1. In Firefox, it's either a Private Browsing tab or after some interaction with the app, idk.
Today tested on a MacOS Monterey 12.0.1 machine in Chromium 96.0.4664.45 & Safari 15.1

P.S. For Safari, Apple's using the 5000 port for their system stuff for some reason, so to get around it, you can add --port 3000 flag

@Andrevwvm
Copy link

vite preview still fails with node v14.18.3 when the https server option enabled.

Node.js v14.18.3
Vite v2.8.0-beta.1
Enabled https

Error:
\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:68637
this._implicitHeader();
^

TypeError: this._implicitHeader is not a function
at Http2ServerResponse.end (C:\Projects\Fenetre.SiliconCore\Source\Fenetre.SiliconCore.Sample.WebVue\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:68637:6)
at Array.write (C:\Projects\Fenetre.SiliconCore\Source\Fenetre.SiliconCore.Sample.WebVue\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:40673:9)
at listener (C:\Projects\Fenetre.SiliconCore\Source\Fenetre.SiliconCore.Sample.WebVue\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:39946:15)
at onFinish (C:\Projects\Fenetre.SiliconCore\Source\Fenetre.SiliconCore.Sample.WebVue\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:39877:5)
at callback (C:\Projects\Fenetre.SiliconCore\Source\Fenetre.SiliconCore.Sample.WebVue\node_modules\vite\dist\node\chunks\dep-e4dc9ea2.js:39738:10)
at Http2ServerRequest.emit (events.js:400:28)
at endReadableNT (internal/streams/readable.js:1334:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)

@hanneswidrig
Copy link

hanneswidrig commented Jan 11, 2022

@Andrevwvm I am also seeing this behavior, my setup is utilizing https: true which I assume is causing problems.

@delebash
Copy link

delebash commented Mar 6, 2022

Any fix for this yet?

@bluwy
Copy link
Member

bluwy commented Mar 6, 2022

Yes. #6557

@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite
Projects
None yet