Skip to content

Add type support for custom scripts configuration in nuxt.config #581

Description

@markmybytes

🆒 Your use case

When I create a custom script, I would expect it works just like a built-in script. Support initialize the custom script in both nuxt.config or app.vue.

exportdefaultdefineNuxtConfig({modules: ['@nuxt/scripts'],compatibilityDate: '2025-07-15',hooks: {'scripts:registry': function(registry){registry.push({category: 'custom',label: 'My Custom Analytics',import: {name: 'useScriptMyCustomScript',from: resolve('./app/composables/useScriptMyCustomScript'),},});},},scripts: {registry: {myCustomScript: {id: 'fake-account-id',},},},});

If the custom is initialized in nuxt.config, TS server will complain:

Object literal may only specify known properties, and 'myCustomScript' does not exist in type 'Partial<{ [x: `${string}-npm`]: any; crisp: any; clarity: any; cloudflareWebAnalytics: any; databuddyAnalytics: any; metaPixel: any; fathomAnalytics: any; plausibleAnalytics: any; googleAdsense: any; googleAnalytics: any; ... 15 more ...; umamiAnalytics: any; }>'.ts(2353)

Although the project can still be ran, and built successfully, and all scripts are configurated, and working properly, it would be nice to have no type error for custom script configuration at the least.

🆕 The solution you'd like

  • no type error when entering configuration for custom script in scripts.registry in nuxt.config.
  • nice if there are autocompletions for the configuration of custom scripts

🔍 Alternatives you've considered

No response

ℹ️ Additional info

This issue is part of this issue, but I think I should mention it separately for easy tracking, and I'm not sure whether this is a bug or an expected behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions