How to use Google GSI in typescript with React?

Viewed 121

I have seen the qustion about this topic. I came to some solution.

First Import the GSI client library in a script tag in HTML,

<script src="https://accounts.google.com/gsi/client"></script>

Next just import the google-one-tap for type support

import * as google from "google-one-tap";

Now I am sure that the GSI client will load but how to suppress the error,

ERROR in ./src/components/Navigation.tsx 24:0-41
Module not found: Error: Can't resolve 'google-one-tap' in 'C:\Users\srilakshmikanthanp\OneDrive\Documents\Source Code\chatviewer\apps\web\src\components'  

I have also tried directly importing from the web like,

import * as google from "https://accounts.google.com/gsi/client";

Add added the type definition via global.d.ts like,

declare module 'https://accounts.google.com/gsi/client' {
  export * from 'google-one-tap'
}

But this too results in,

ERROR in external "https://accounts.google.com/gsi/client"
The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script

I tried to fix that by changing the target to es2020 but no results. Now how to successfully import the GSI client to React in typescript ? Thanks.

0 Answers
Related