N
Nuxt7mo 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',
});
},
});
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',
});
},
});
4 Replies
Gerbuuun
Gerbuuun7mo ago
It does not recognise runtimeConfig.mollie:
Argument of type 'unknown' is not assignable to parameter of type 'IgnoredInput | Input'.
Argument of type 'unknown' is not assignable to parameter of type 'IgnoredInput | Input'.
This is literally a copy from the Nuxt documentation Also, the server handlers do not exist when I try to call them in my project...
Tanuki
Tanuki6mo ago
Hello, did you managed to fix this error ? I have the same right now 🤔 @Gerbuuun So for the moment i've just added
declare module 'nuxt/schema' {
interface PublicRuntimeConfig {
metaPixel: ModuleOptions
}
}
declare module 'nuxt/schema' {
interface PublicRuntimeConfig {
metaPixel: ModuleOptions
}
}
Gerbuuun
Gerbuuun6mo ago
I gave up lol
Tanuki
Tanuki6mo ago
use the solution i used until we get out of this!
Want results from more Discord servers?
Add your server