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

http2 module not found #1474

Closed
AndreiEnache opened this issue Mar 28, 2019 · 13 comments · May be fixed by ajesse11x/core#1
Closed

http2 module not found #1474

AndreiEnache opened this issue Mar 28, 2019 · 13 comments · May be fixed by ajesse11x/core#1

Comments

@AndreiEnache
Copy link

AndreiEnache commented Mar 28, 2019

After updating from superagent@4.1.0 to 5.0.0 in create-react-app with typescript I'm running into an error:

./node_modules/superagent/lib/node/http2wrapper.js
Module not found: Can't resolve 'http2' in '{redacted}\node_modules\superagent\lib\node'

Downgrading back to 4.1.0 solves this problem

@rux
Copy link

rux commented Mar 28, 2019

I have seen exactly the same thing. My preliminary research looks like it has something to do with create-react-app interfering with the http2 module, though it's a bit beyond my comprehension the reasons for doing this. facebook/create-react-app#5686 seems to reference the problem.

@fmal
Copy link

fmal commented Mar 28, 2019

@AndreiEnache @rux @niftylettuce i guess with 5.0.0 it's required to make alias in webpack config such as:

resolve: {
  alias: {
    superagent: 'node_modules/superagent/lib/client' // or node_modules/superagent/dist/superagent.js
  }
}

i was hoping that there would something like dist/es folder where sources transpiled by Babel would be kept (as ES modules) and package.json could use module field to point to that folder, so it would be automatically picked by webpack. That's what you usually expect when bundling package from NPM.

@AndreiEnache
Copy link
Author

You can't modify the webpack config unless you eject the CRA which I'd rather not do

@fmal
Copy link

fmal commented Mar 28, 2019

@AndreiEnache maybe you could try import superagent from 'superagent/dist/superagent then? 😃

@AndreiEnache
Copy link
Author

AndreiEnache commented Mar 28, 2019

@AndreiEnache maybe you could try import superagent from 'superagent/dist/superagent then? 😃

CRA handles linking correctly - I did try it just in case and it's still no go.

I have seen exactly the same thing. My preliminary research looks like it has something to do with create-react-app interfering with the http2 module, though it's a bit beyond my comprehension the reasons for doing this. facebook/create-react-app#5686 seems to reference the problem.

Thank you for the reference. It seems this is the right path to take:

This is probably as "temporary" as it gets, it papers over a problem that really lies in the usage of certain modules -- as HTTP2 is not implemented in the browser, if you're using a module that depends on it, either (a) you should not be using it or (b) the module authors themselves should be taking steps to making their module web-compatible, whether that means conditionally requiring http2 or something more involved.

@AndreiEnache
Copy link
Author

I managed to get a way with only a warning by surrounding the http2 require in a try-catch in http2wrapper.js

let http2 = {};
try {
  http2 = require('http2');
} catch (e) {
  console.log(e);
}

and by commenting
if (global.GENTLY) require = GENTLY.hijack(require);
from formidable in incoming_form.js, file.js, querystring_parser.js and json_parser.js
but I'm guessing a cleaner way is needed

@niftylettuce
Copy link
Collaborator

niftylettuce commented Mar 28, 2019

Your Node version needs to be at least v8.4.0, we recommend using at least v8.8.1.

Please try v5.0.1

The 'http2' is not supported until Node.js 8.4.0, though it's not stable until v10.10.0.

@AndreiEnache
Copy link
Author

As I said in the OP, I'm running this in the browser (it's a react app bootstrapped by create-react-app)

@niftylettuce
Copy link
Collaborator

v5.0.1 is released and it has fixed this issue. This package also works again without throwing this error in Node versions v6.4.0 to v8.x.

npm install superagent@latest

or with yarn:

yarn add superagent@latest

let me know if any further issues. you should not need any workarounds.

@AndreiEnache
Copy link
Author

AndreiEnache commented Mar 28, 2019

Sadly v5.0.1 doesn't fix this issue as it is not related to node. To prove a point, I updated to 5.0.1 and I'm not getting the This version of node is not supported but rather keep getting Module not found: Can't resolve 'http2' in ...
Just to make sure that we're on the same page - I'm trying to run superagent in a browser, not on a server.
You should be able to see that it errors out here as well (albeit with no readable error message).
https://codesandbox.io/s/ww8xjq0qw7
(5.0.1 isn't indexed yet by codesandbox but you can update the version easily by clicking the Dependencies -> Refresh icon near superagent)

@niftylettuce
Copy link
Collaborator

@AndreiEnache please try v5.0.2 (just released!) and get back to me - thank you for reporting.

We were missing a line in browser config in package.json that would have instructed webpack (in your case) to require the client-side version ./lib/client.js as opposed to ./lib/node/index.js.

See ccc7f56

@niftylettuce
Copy link
Collaborator

I have also just unpublished v5.0.0 and v5.0.1 from NPM to prevent further headache.

@AndreiEnache
Copy link
Author

It's fixed.

Thank you!

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

Successfully merging a pull request may close this issue.

4 participants