Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't configure custom registry script in nuxt.config.ts (myCustomScript is not defined) #270

Closed
bernhardberger opened this issue Sep 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bernhardberger
Copy link
Contributor

🐛 The bug

myCustomScript is not defined

at eval (./virtual:nuxt:/home/projects/nuxt-starter-pkwfkx/.nuxt/plugins/server.mjs#cjs:40:89)
at Module.executeAsync (./node_modules/.pnpm/[email protected]/node_modules/unctx/dist/index.mjs:130:19)
at setup (./virtual:nuxt:/home/projects/nuxt-starter-pkwfkx/.nuxt/plugins/server.mjs#cjs:40:65)
at eval (./node_modules/.pnpm/[email protected][email protected]/node_modules/nuxt/dist/app/nuxt.js#cjs:141:60)
at fn (./node_modules/.pnpm/[email protected][email protected]/node_modules/nuxt/dist/app/nuxt.js#cjs:223:44)
at Object.callAsync (./node_modules/.pnpm/[email protected]/node_modules/unctx/dist/index.mjs:87:55)
at eval (./node_modules/.pnpm/[email protected][email protected]/node_modules/nuxt/dist/app/nuxt.js#cjs:226:56)
at Object.runWithContext (./node_modules/.pnpm/@[email protected]/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js#cjs:3903:18)
at callWithNuxt (./node_modules/.pnpm/[email protected][email protected]/node_modules/nuxt/dist/app/nuxt.js#cjs:226:24)
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  modules: [
    '@nuxt/scripts',
    './modules/my-custom-registry-script-module/src/module.ts',
  ],

  scripts: {
    registry: {
      myCustomScript: {
        src: 'https://example.com/some-bogus-source.js',
      },
    },
  },

  compatibilityDate: '2024-08-21',
});

🛠️ To reproduce

https://stackblitz.com/edit/nuxt-starter-yxpzcr?file=nuxt.config.ts

🌈 Expected behavior

I have extended the Script Registry through the scripts:registry hook in a custom module. I expect it to be configurable in nuxt.config.ts via scripts.registry.myCustomModule key (see linked reproduction).

ℹ️ Additional context

No response

@bernhardberger bernhardberger added the bug Something isn't working label Sep 17, 2024
@bernhardberger
Copy link
Contributor Author

bernhardberger commented Sep 17, 2024

I was led to believe that the scripts:registry was an object by the docs: https://scripts.nuxt.com/docs/api/nuxt-hooks

However, in reality, it's just an array and my custom entry was never added...

this works:

nuxt.hooks.hook('scripts:registry', async (registry) => {
      registry.push({
        // used in DevTools
        label: 'OneTrust SDK',
        logo: ``,
        src: false,
        category: 'consent-management',
        import: onetrustRegistry.import,
      })
    })

A lot of confusion created by: #267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant