2

I am trying to use google api with a next.js app. I was reading the documentation and the next.js recommendation for implementing google api is to use next.js Head component. I loaded the script but can't seem to access the gapi property...

export default () => (
  <div>
    <Head>
      <link href="/static/styles.css" rel="stylesheet" />
      <script
        src="https://apis.google.com/js/platform.js?onload=init"
        async
        defer
      ></script>
    </Head>
    <Login />
  </div>
);

My GoogleClient file starts with

const GoogleClient = ({api}) => {
...
}

I used a Login component that initializes the GoogleClient file as

const Login = () => {
    useEffect(()=> {
        GoogleClient(window.gapi)
    }, [])
...
}

When I console.log window the gapi property exists on the window object but when I call window.gapi I get the following error --> Property 'gapi' does not exist on type 'Window & typeof globalThis'. I googled the error but haven't seen any posts on how to fix it.

1 Answer 1

2

It turns out this was a duplicate error to other posts. I needed to install @types/gapi or @types/gapi.auth2 packages.

If you install the later, you would not need the former.

npm install @types/gapi.auth2 -D
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.