{"record":{"id":"d541ae0630038198","repo":"vuejs/core","slug":"vue-compiler-sfc-sfc-contains-no-script-tags","errorCode":null,"errorMessage":"[@vue/compiler-sfc] SFC contains no <script> tags.","messagePattern":"\\[@vue/compiler-sfc\\] SFC contains no <script> tags\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/compiler-sfc/src/compileScript.ts","lineNumber":197,"sourceCode":"\n  const { script, scriptSetup, source, filename } = sfc\n  const hoistStatic = options.hoistStatic !== false && !script\n  const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''\n  const scriptLang = script && script.lang\n  const scriptSetupLang = scriptSetup && scriptSetup.lang\n  const isJSOrTS =\n    isJS(scriptLang, scriptSetupLang) || isTS(scriptLang, scriptSetupLang)\n\n  if (script && scriptSetup && scriptLang !== scriptSetupLang) {\n    throw new Error(\n      `[@vue/compiler-sfc] <script> and <script setup> must have the same ` +\n        `language type.`,\n    )\n  }\n\n  if (!scriptSetup) {\n    if (!script) {\n      throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`)\n    }\n\n    // normal <script> only\n    if (script.lang && !isJSOrTS) {\n      // do not process non js/ts script blocks\n      return script\n    }\n\n    const ctx = new ScriptCompileContext(sfc, options)\n    return processNormalScript(ctx, scopeId)\n  }\n\n  if (scriptSetupLang && !isJSOrTS) {\n    // do not process non js/ts script blocks\n    return scriptSetup\n  }\n\n  const ctx = new ScriptCompileContext(sfc, options)","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/vuejs/core/blob/a2b40db9a83b36ed9da3a16403cf8f040262d73f/packages/compiler-sfc/src/compileScript.ts#L179-L215","documentation":"Thrown by compileScript in @vue/compiler-sfc when the SFC has neither a <script setup> nor a normal <script> block. compileScript exists to transform script blocks; with nothing to transform it cannot produce a component module. The guard at compileScript.ts:197 fires inside the !scriptSetup / !script branch.","triggerScenarios":"Calling compileScript() on an SFC whose source only contains <template> and/or <style>; passing an SFC descriptor that was parsed from a template-only or style-only file.","commonSituations":"A genuinely script-less SFC being fed through a codegen pipeline that assumes a script block; a build tool (Vite plugin, vue-loader) invoking compileScript unconditionally for every .vue file including ones intended to be template/style only; a malformed SFC where the script tag was stripped by a preprocessor.","solutions":["If the SFC is intentionally script-less, skip compileScript and rely on compileTemplate/compileStyle only.","Add a <script setup> block (even an empty one) to give the SFC a component module.","In build-tool integration code, gate the compileScript call on sfc.script || sfc.scriptSetup before invoking it.","Verify the SFC source was not corrupted by a preprocessor that removed the script block."],"exampleFix":"// before\n<template><div>hi</div></template>\n<style>.x{}</style>\n\n// after\n<template><div>hi</div></template>\n<script setup lang=\"ts\"></script>\n<style>.x{}</style>","handlingStrategy":"validation","validationCode":"// Only call compileScript when there is something to compile.\nfunction shouldCompileScript(sfc: { script?: unknown; scriptSetup?: unknown }) {\n  return !!(sfc.script || sfc.scriptSetup)\n}\n// usage:\nif (shouldCompileScript(sfc)) {\n  compileScript(sfc, opts)\n}","typeGuard":"function sfcHasScript(sfc: { script?: unknown; scriptSetup?: unknown }): boolean {\n  return Boolean(sfc?.script || sfc?.scriptSetup)\n}","tryCatchPattern":null,"preventionTips":["Gate compileScript on the presence of a script block in build-tool integration code.","Document which .vue files are expected to be template/style-only.","Validate SFC structure right after parse() and before compileScript()."],"tags":["vue","compiler-sfc","sfc","script-setup","configuration"],"backgroundTag":null,"analyzedSha":"a2b40db9a83b36ed9da3a16403cf8f040262d73f","analyzedAt":"2026-08-12T14:21:14.989Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}