nuxt / scripts

Third-Party Scripts Meets Nuxt Developer Experience.
https://scripts.nuxt.com
MIT License
331 stars 45 forks source link

bundler-transformer error with array syntax for globals #121

Closed vejja closed 4 months ago

vejja commented 4 months ago

I'm trying to load CF Turnstile with the following configuration :

export default defineNuxtConfig({
  scripts: {
      globals: [
        [ 
          { 
            src: 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit'
          }, 
          {
            use: () => {
              //@ts-expect-error
              return window.turnstile
            }
          }
        ]
      ]
    }
})

I'm getting the following error:

Capture d’écran 2024-07-02 à 00 46 25

Looks like an extra closing bracket is being inserted at the end of the useScript function in the virtual plugin ?

vejja commented 4 months ago

Probably similar to #115

Tentatively blaming https://github.com/nuxt/scripts/blob/db571cf4b4d00b0c080ccce88988bb5ec01a02c8/src/module.ts#L216

harlan-zw commented 4 months ago

Thanks for the report, this is indeed a duplicate of #115.

However, I will note that we can only support serializable data within the nuxt config. So anything using functions isn't supported, I've included type improvements around this.

I'm putting some more thought into the API around the globals so may look a bit different soon.

vejja commented 4 months ago

Ok understood Let’s close then?