NuxtN
Nuxt2y ago
Gerbuuun

Nuxt Module `runtimeConfig` types.

How do I get the module.ts file to recognize the runtimeConfig type? Obviously it does not exists because there is no
nuxt.config.ts
but I cannot build the module because of this type error...

export default defineNuxtModule<ModuleOptions>({
  meta: {
    name: '@gerbuuun/mollie',
    version: '0.0.1',
    configKey: 'mollie',
    compatibility: {
      nuxt: '^3.11.1',
    },
  },
  defaults: {
    scope: ['organizations.read'],
    redirectUrl: '/',
    authorizationParams: undefined,
  },
  setup(options, nuxt) {
    const resolver = createResolver(import.meta.url);

    const runtimeConfig = nuxt.options.runtimeConfig;
    runtimeConfig.mollie = defu(runtimeConfig.mollie, {
      scope: options.scope,
      redirectUrl: options.redirectUrl,
      authorizationParams: options.authorizationParams,
      clientId: '',
      clientSecret: '',
    });

    // Server
    if (nuxt.options.nitro.imports !== false) {
      nuxt.options.nitro.imports = defu(nuxt.options.nitro.imports, {
        presets: [
          {
            from: resolver.resolve('./runtime/server/utils/client'),
            imports: ['useMollie'],
          },
        ],
      });
    }

    // Routes
    addServerHandler({
      handler: resolver.resolve('./runtime/server/api/authorize.get'),
      route: '/api/_mollie/authorize',
      method: 'GET',
    });
    addServerHandler({
      handler: resolver.resolve('./runtime/server/api/redirect.get'),
      route: '/api/_mollie/redirect',
      method: 'GET',
    });
  },
});
Was this page helpful?