1

I attempted to add the Google Identity services script to nuxt.config.ts, which should expose window.google.

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
    /* snip /*
    head: {
        script: [
            { src: "https://accounts.google.com/gsi/client" },
        ],
    },
});

However, when I try to use it inside of a component, google is undefined.

<script setup lang="ts">
/* snip */

onMounted(() => {
    // google is not defined
    google.accounts.id.initialize({
        client_id: "id.apps.googleusercontent.com",
        callback: signInNew,
    });

    google.accounts.id.renderButton(document.getElementById("signIn")!, {
        type: "standard",
    });
    google.accounts.id.prompt();
});
</script>

Upon further inspection, I found that the script is not added to the head at all. How can I fix this?

1
  • did you put it in side the nuxt.config file? app : { head : script : [ { src .. Commented Oct 5, 2022 at 0:51

1 Answer 1

1

You may try the following way.

export default defineNuxtConfig({
    app: {
      head: {
          script: [
              { src: "https://accounts.google.com/gsi/client" },
          ],
      },
    }
});

Sign up to request clarification or add additional context in comments.

1 Comment

Thank @henrykohl adding the head to app instead of directly to the root of the config worked for Nuxt3

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.