diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts
index 434153eef9ba..84b8c7171849 100644
--- a/packages/nuxt/src/components/islandsTransform.ts
+++ b/packages/nuxt/src/components/islandsTransform.ts
@@ -33,6 +33,7 @@ const SCRIPT_RE = /')
+ } else {
+ s.replace(SCRIPT_RE, (full) => {
+ return full + IMPORT_CODE
+ })
+ }
+
let hasNuxtClient = false
diff --git a/packages/nuxt/test/islandTransform.test.ts b/packages/nuxt/test/islandTransform.test.ts
index 1ce358d5da90..843319ca75e7 100644
--- a/packages/nuxt/test/islandTransform.test.ts
+++ b/packages/nuxt/test/islandTransform.test.ts
@@ -317,6 +317,31 @@ describe('islandTransform - server and island components', () => {
"
`)
})
+
+ it('should add import if there is no scripts in the SFC', async () => {
+ const result = await viteTransform(`
+
+
+
+
+
+
+ `, 'hello.server.vue', false, true)
+
+ expect(result).toMatchInlineSnapshot(`
+ "
+
+
+
+
+
+
+ "
+ `)
+ expect(result).toContain(`import NuxtTeleportSsrClient from '#app/components/nuxt-teleport-ssr-client'`)
+ })
})
describe('webpack', () => {