{"record":{"id":"17f68b78ab708937","repo":"vuejs/vue","slug":"function-template-is-only-supported-in-rendertostr","errorCode":null,"errorMessage":"function template is only supported in renderToString.","messagePattern":"function template is only supported in renderToString\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server-renderer/src/create-renderer.ts","lineNumber":143,"sourceCode":"      if (context) {\n        templateRenderer.bindRenderFns(context)\n      }\n      const renderStream = new RenderStream((write, done) => {\n        // @ts-expect-error\n        render(component, write, context, done)\n      })\n      if (!template) {\n        // @ts-expect-error\n        if (context && context.rendered) {\n          // @ts-expect-error\n          const rendered = context.rendered\n          renderStream.once('beforeEnd', () => {\n            rendered(context)\n          })\n        }\n        return renderStream\n      } else if (typeof template === 'function') {\n        throw new Error(\n          `function template is only supported in renderToString.`\n        )\n      } else {\n        const templateStream = templateRenderer.createStream(context)\n        renderStream.on('error', err => {\n          templateStream.emit('error', err)\n        })\n        renderStream.pipe(templateStream)\n        //@ts-expect-error\n        if (context && context.rendered) {\n          //@ts-expect-error\n          const rendered = context.rendered\n          renderStream.once('beforeEnd', () => {\n            rendered(context)\n          })\n        }\n        return templateStream\n      }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/vuejs/vue/blob/9e88707940088cb1f4cd7dd210c9168a50dc347c/packages/server-renderer/src/create-renderer.ts#L125-L161","documentation":"Thrown synchronously from renderer.renderToStream when the template option is a function. Function templates require the full rendered content up front (they receive content + context and return a string or promise), but renderToStream pipes output incrementally through a TemplateStream — there is no single moment where the complete content is available to hand to a function. Only renderToString supports function templates because it accumulates the full string first.","triggerScenarios":"Calling renderer.renderToStream(app, context) on a renderer created with { template: (content, ctx) => html } where template is a function rather than a string.","commonSituations":"Developer reuses a renderer configured for renderToString (with a function template) and calls renderToStream on the same instance. Migrating from string template to programmatic template without realizing stream rendering doesn't support it.","solutions":["Use renderToString instead of renderToStream when a function template is required.","If streaming is mandatory, switch the template to a string (HTML with <!--vue-ssr-outlet--> placeholder) so createStream can build a TemplateStream.","Create two renderers: one with a string template for streaming, one without a template and do post-processing on the stream manually."],"exampleFix":"// before\nconst renderer = createRenderer({\n  template: (content, ctx) => `<html>...${content}...</html>`\n})\nrenderer.renderToStream(app) // throws\n\n// after — use renderToString for function templates\nrenderer.renderToString(app, (err, html) => { /* ... */ })","handlingStrategy":"validation","validationCode":"function assertTemplateCompatibleWithStream(template: unknown): void {\n  if (typeof template === 'function') {\n    throw new Error(\n      'Function templates are not supported by renderToStream. Use renderToString, or pass a string template.'\n    )\n  }\n}\n\nassertTemplateCompatibleWithStream(rendererOptions.template)\nrenderer.renderToStream(app)","typeGuard":"function isStreamCompatibleTemplate(template: unknown): boolean {\n  return template === undefined || typeof template === 'string'\n}","tryCatchPattern":"try {\n  renderer.renderToStream(app, context)\n} catch (e) {\n  if (e.message.includes('function template is only supported in renderToString')) {\n    // fall back to renderToString\n    renderer.renderToString(app, context, cb)\n  } else {\n    throw e\n  }\n}","preventionTips":["Use two renderer instances: one for stream (string template), one for toString (function template).","Document which render method each renderer is configured for.","Add a startup assertion: if template is a function, warn that renderToStream is unavailable."],"tags":["ssr","render-to-stream","template","streaming","api-mismatch"],"analyzedSha":"9e88707940088cb1f4cd7dd210c9168a50dc347c","analyzedAt":"2026-08-11T22:22:01.295Z","schemaVersion":2},"datasetVersion":"2026-08-12T05:08:24.936Z"}