diff --git a/.changeset/eight-swans-destroy.md b/.changeset/eight-swans-destroy.md
new file mode 100644
index 00000000000..6f56edffaa1
--- /dev/null
+++ b/.changeset/eight-swans-destroy.md
@@ -0,0 +1,5 @@
+---
+'graphql-language-service-server': patch
+---
+
+fix: vue and svelte files doesn't log errors anymore when parsing with no script tag (#2836)
diff --git a/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts b/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts
index 48bd37be429..15aac193bb1 100644
--- a/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts
+++ b/packages/graphql-language-service-server/src/__tests__/findGraphQLTags-test.ts
@@ -289,6 +289,72 @@ query {id}
query {id}`);
});
+ it('no crash in Svelte files without `;
+
+ const consoleErrorSpy = jest
+ .spyOn(process.stderr, 'write')
+ .mockImplementation(() => true);
+
+ const contents = baseFindGraphQLTags(
+ text,
+ '.svelte',
+ '',
+ new Logger(tmpdir(), false),
+ );
+ // We should have no contents
+ expect(contents).toMatchObject([]);
+
+ // Nothing should be logged as it's a managed error
+ expect(consoleErrorSpy.mock.calls.length).toBe(0);
+
+ consoleErrorSpy.mockRestore();
+ });
+
+ it('no crash in Svelte files with empty `;
+
+ const consoleErrorSpy = jest
+ .spyOn(process.stderr, 'write')
+ .mockImplementation(() => true);
+
+ const contents = baseFindGraphQLTags(
+ text,
+ '.svelte',
+ '',
+ new Logger(tmpdir(), false),
+ );
+ // We should have no contents
+ expect(contents).toMatchObject([]);
+
+ // Nothing should be logged as it's a managed error
+ expect(consoleErrorSpy.mock.calls.length).toBe(0);
+
+ consoleErrorSpy.mockRestore();
+ });
+
it('finds multiple queries in a single file', async () => {
const text = `something({
else: () => gql\` query {} \`
diff --git a/packages/graphql-language-service-server/src/findGraphQLTags.ts b/packages/graphql-language-service-server/src/findGraphQLTags.ts
index a73c757d4b5..5dfd5db8894 100644
--- a/packages/graphql-language-service-server/src/findGraphQLTags.ts
+++ b/packages/graphql-language-service-server/src/findGraphQLTags.ts
@@ -90,6 +90,16 @@ function parseVueSFC(source: string): ParseVueSFCResult {
try {
scriptBlock = VueParser.compileScript(descriptor, { id: 'foobar' });
} catch (error) {
+ if (
+ error instanceof Error &&
+ error.message === '[@vue/compiler-sfc] SFC contains no