The 'http2' module is not supported by Forge

I want to use googleapis module for authentication and calling google APIs in a Forge app. Here is a code snippet.

const { google } = require("googleapis");

export const authenticate = async (credentials) => {
    try {
        const client = new google.auth.JWT({
            email: credentials.client_email,
            key: credentials.private_key,
            scopes: AUTH_SCOPES,
        });
        const resp = await client.authorize();
        console.log("auth response =>", resp);
        return true;
    }
    catch (err) {
        console.error(`Error in Authentication : ${err.message}`);
        return false;
    }
};

When I try to deploy, it works but it gives the below warning.

WARN    ⚠️  the 'http2' module is not supported by Forge, please refer to the documentation at https://go.atlassian.com/forge-runtime-js-environment

Is there a way to resolve this warning?
Will it cause any issues when publishing the app to the marketplace?

Hi @SagarGujarati ,

As the linked documentation mentions, the http2 module is not supported on Forge. This is because Forge apps do not execute in a true Node.js runtime, but instead execute in a vanilla JavaScript sandbox - some built-in libraries and features of Node are not available in Forge.

Since the googleapis module has a depending on the http2 module, it won’t work when used within a Forge app.

You could try using the Google APIs vanilla JavaScript API instead, which does not require any Node.js modules to function.

We are working to improve the Forge runtime to fully support all Node.js features, which is being tracked here: Trello

1 Like

Hi @HeyJoe ,

Thanks for the reply,

There is an option we can set to disable http2 while using googleapis. Below is the code snippet:

const { google } = require("googleapis");
google.options({
    http2: false
});

I tried this and I am able to call API successfully and I am getting proper responses. But the warning still persists.
Should I switch to google-api-javascript-client even if I get the proper API response?

1 Like

@SagarGujarati - that sounds like it would be fine, as long as you trust that option works as described. The Forge CLI can only detect incompatible libraries by statically analysing your projects dependency tree - if you are confident that the dependency is not actually invoked at runtime, then it’s safe to ignore the warning. :+1:

3 Likes