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

Error: Missing IncomingMessage property on http2 module? #3

Open
talwaserman opened this issue Nov 6, 2018 · 7 comments
Open

Error: Missing IncomingMessage property on http2 module? #3

talwaserman opened this issue Nov 6, 2018 · 7 comments

Comments

@talwaserman
Copy link

getting the following error
Error: Missing IncomingMessage property on http2 module?
npm verison: 6.4.1
node version: 11.1.0
express: 4.15.4

@SangeetaKhan
Copy link

SangeetaKhan commented Nov 6, 2018

Yeah even I am getting the same error. Tried working with the requestHTTP2 and responseHTTP2 methods, but failed. Needs help.

screen shot 2018-11-06 at 1 44 55 pm

@Abourass
Copy link

Abourass commented Nov 6, 2018

Same.

@Jashepp
Copy link
Owner

Jashepp commented Nov 7, 2018

NodeJS version 11.0.0+ has a core http2 module (previously hidden behind --expose-http2 command-line option).
Using require('http2') will use that core module instead of molnarg's node-http2 module (which is now deprecated).

You may need to require the old http2 module via a relative or fixed path instead then pass it to express-http2-workaround.
I need to update this to check if the core module is passed in or not, to have a more relevant error message be thrown. I'll update the README to mention this information too when I can.

@talwaserman
Copy link
Author

can you please provide code snippet of the solution?
is there also a way to use this workaround with the new http2 module ?

@SangeetaKhan
Copy link

Any update on this ?

@SangeetaKhan
Copy link

@Jashepp Please share me any code for the same

@niklasHagner
Copy link

niklasHagner commented Jan 8, 2020

Stumbled upon this thread as I googled for this specific error.
I had an old project that hadn't been updated since 2017 and while running it with node 10 I got the error. (It did work fine on older versions like version 7 though)

As Jasheep said the issue is that node (since version 10 LTS) now has a native http2 so require("http2") will load that one. instead of https://www.npmjs.com/package/http2

The solution is to replace require("http2"); with require("./node_modules/http2"); and all the code examples from the readme will work fine.

@Jashepp - I know this project hasn't been updated in a long time but a suggestion be to update the code in the README with this small change.


So @SangeetaKhan , @talwaserman - the code sample from https://github.com/Jashepp/express-http2-workaround#example works if you just change the path for the http2 import.

Here's a full example I used, works fine in node 10.16.3.

var express = require('express');
var http2 = require("./node_modules/http2"); //here's the significant change! this loads the module from https://www.npmjs.com/package/http2 instead of node's built-in
var fs = require("fs");
var app = express();

// Make HTTP2 work with Express (this must be before any other middleware)
require('express-http2-workaround')({ express:express, http2:http2, app:app });

// Setup HTTP/2 Server
var httpsOptions = {
    'key' : fs.readFileSync(__dirname + '/keys/ssl.key'),
    'cert' : fs.readFileSync(__dirname + '/keys/ssl.crt'),
    'ca' : fs.readFileSync(__dirname + '/keys/ssl.crt')
};
var http2Server = http2.createServer(httpsOptions,app);
var port = 5000;
http2Server.listen(port,function(){
  console.log("Express HTTP/2 server started on", port);
});

// Serve some content
app.get('/', function(req,res){
    res.send('Hello World!');
});

Browse to https://localhost:5000 to view the output.

PS: the original example uses 443 but some machines have permission denied for those ports so I changed it to a random one like 5000.
DS: make sure you use https and not http as this example only sets up the https-variant.

Jashepp added a commit that referenced this issue Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants