Grpc-node: Module 'http2' not found

Created on 2 Nov 2018  路  21Comments  路  Source: grpc/grpc-node

Problem description

gRPC couldn't initialize due to the missing 'http2' module.

Reproduction steps

  • Use of package firebase-admin in React App, bootstrapped with create-react-app
  • Follow steps from Google Firebase Admin Documentation
  • Start the React App using yarn start or npm start

Environment

  • Linux Ubuntu 18.04 amd64
  • Node version 10.11.0
  • npm

Error message

Failed Compiling
./node_modules/@grpc/grpc-js/build/src/channel.js
Module not found: Can't resolve 'http2' in '/home/.../project1/node_modules/@grpc/grpc-js/build/src'
requires reporter action

Most helpful comment

I had same issue, installed manually deprecated package of http2 to bypass that error with npm install http2.
I hope they add that module soon in create-react-app

All 21 comments

How did you install the Node runtime?

Followed the standard installation guide here

What does node -p process.version and node -p http2 display? The http2 module is built into Node core, so if you're actually using version 10.11.0, then it should be there.

node -p process.version: outputs v10.11.0
node -p http2: outputs a list of constants.

So, we'd need a more complete reproduction case. The http2 module seems to be working properly for you, so it failing like this doesn't make a lot of sense.

create-react-app seems to hardcode a list of Node built-in modules for which it creates empty mocks: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/webpack.config.dev.js#L451-L457

My guess is that this problem manifested because they haven't added http2 to the list yet.

Edit: https://github.com/facebook/create-react-app/pull/5686

If you're using gRPC in a context where you need an empty http2 mock to load it, gRPC won't work because it fundamentally needs http2 to function.

I'd also add that you can't make grpc work from the browser in any case. In other words, grpc can't be webpack-ed, therefore, you can't use it in a "react application" out of the box like this.

I'd imagine that grpc is only there as a dependency of firebase-admin rather than the app itself, and that webpack would compile but then prune it, so its inclusion would be inconsequential from the app developer's point of view. But now since the invocation of webpack in create-react-app doesn't know that http2 is a core module, it'll crash instead while compiling. (This is my guess)

If firebase-admin is not a necessary dependency of the app, then the correct solution is to omit it from the app, not to force it compile when you know that it won't function.

It seems like the module isn't supported on the client side: https://www.npmjs.com/package/firebase-admin#supported-environments

this issue is related to any library that depends on google-gax, so it is not specific to firebase-admin. For example, I am trying to use @google-cloud/vision. As noted, mocking http2 in webpack does not work. @google-cloud/vision is a client-side API, so it should work in the browser, no?

I guess that one way forward for browser support for google-gax is grpc-web?

:(

I had same issue, installed manually deprecated package of http2 to bypass that error with npm install http2.
I hope they add that module soon in create-react-app

IiroNiemi Thanks

This happened after I installed the firebase deployment CLI today ( ? odd ). resolved by :

i) npm install http2
ii) npm uninstall firebase-admin ( personally can see how this is related, but was referred to in some stackoverflow answers )

In my case the reason for "Module 'http2' not found" error was too old version of node - 8.4.x - set in package.json and used by heroku. It seems http2 was added by default in 8.8.0. Updating node version to 12.x.x and npm to 6.x.x solved the problem.

I think @philval is correct the problem comes from firebase-admin. Looks very similar to that
https://github.com/googleapis/nodejs-dialogflow/issues/314
Anyone found a way to use create-react-app with firebase-admin? To reproduce do:
npm install firebase admin
then in your code
var admin = require("firebase-admin");

Has this issue been resolved?

This "issue" is just that there are some environments where the @grpc/grpc-js library is not supported. The library is only intended to function on Node versions specified in the engines field in the package.json file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhanpiti picture nhanpiti  路  3Comments

samiq picture samiq  路  5Comments

Harmonickey picture Harmonickey  路  6Comments

samuela picture samuela  路  4Comments

respinha picture respinha  路  6Comments