From b6d33506ab38eaa041a5d4934219122b9a74196f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 19 Aug 2024 10:38:03 +0100 Subject: [PATCH] fix(nuxt): avoid stripping js extensions in plugin injections (#28593) --- packages/nuxt/src/core/templates.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 3410b6699f..3c7e83a243 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -96,6 +96,8 @@ export const serverPluginTemplate: NuxtTemplate = { }, } +const TS_RE = /\.[cm]?tsx?$/ + export const pluginsDeclaration: NuxtTemplate = { filename: 'types/plugins.d.ts', getContents: async ({ nuxt, app }) => { @@ -124,9 +126,14 @@ export const pluginsDeclaration: NuxtTemplate = { } if (exists(pluginPath)) { - tsImports.push(relativePath.replace(EXTENSION_RE, '')) - continue + if (TS_RE.test(pluginPath)) { + tsImports.push(relativePath.replace(EXTENSION_RE, '')) + continue + } + tsImports.push(relativePath) } + + // No declaration found that TypeScript can use } return `// Generated by Nuxt'