From 0758161c198e6b0d2c0986c3f7f1d664342ff63b Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Thu, 18 Sep 2025 09:35:24 +1000 Subject: [PATCH] fix: add TypeScript path mapping for Nuxt 4 compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add TypeScript path mapping configuration to ensure #nuxt-scripts/* imports work correctly in Nuxt 4. - Add prepare:types hook to configure TypeScript paths - Ensure #nuxt-scripts/* resolves to runtime/* in TypeScript configuration - Maintains backward compatibility with Nuxt 3.16+ Resolves #483 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/module.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/module.ts b/src/module.ts index 092d355a..00b10bda 100644 --- a/src/module.ts +++ b/src/module.ts @@ -108,6 +108,17 @@ export default defineNuxtModule({ const { version, name } = await readPackageJSON(await resolvePath('../package.json')) nuxt.options.alias['#nuxt-scripts-validator'] = await resolvePath(`./runtime/validation/${(nuxt.options.dev || nuxt.options._prepare) ? 'valibot' : 'mock'}`) nuxt.options.alias['#nuxt-scripts'] = await resolvePath('./runtime') + + // Ensure TypeScript path mapping for Nuxt 4 compatibility + nuxt.hooks.hook('prepare:types', async (options) => { + // Ensure paths are configured in TypeScript + if (options.tsConfig?.compilerOptions?.paths) { + options.tsConfig.compilerOptions.paths['#nuxt-scripts/*'] = [ + await resolvePath('./runtime/*'), + ] + } + }) + logger.level = (config.debug || nuxt.options.debug) ? 4 : 3 if (!config.enabled) { // TODO fallback to useHead?