{"record":{"id":"9c54ef6e45e56b9b","repo":"vitejs/vite","slug":"runtime-result-runtime-is-not-supported-9c54ef","errorCode":null,"errorMessage":"{ runtime: \"${result.runtime}\" } is not supported for assets in ${hostType} files: ${filename}","messagePattern":"(.+?) is not supported for assets in (.+?) files: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/build.ts","lineNumber":1719,"sourceCode":"  filename: string,\n  type: 'asset' | 'public',\n  hostId: string,\n  hostType: 'js' | 'css' | 'html',\n  config: ResolvedConfig,\n  toRelative: (filename: string, hostId: string) => string,\n): string {\n  const { renderBuiltUrl } = config.experimental\n  let relative = config.base === '' || config.base === './'\n  if (renderBuiltUrl) {\n    const result = renderBuiltUrl(filename, {\n      hostId,\n      hostType,\n      type,\n      ssr: !!config.build.ssr,\n    })\n    if (typeof result === 'object') {\n      if (result.runtime) {\n        throw new Error(\n          `{ runtime: \"${result.runtime}\" } is not supported for assets in ${hostType} files: ${filename}`,\n        )\n      }\n      if (typeof result.relative === 'boolean') {\n        relative = result.relative\n      }\n    } else if (result) {\n      return result\n    }\n  }\n  if (relative && !config.build.ssr) {\n    return toRelative(filename, hostId)\n  } else {\n    return joinUrlSegments(config.decodedBase, filename)\n  }\n}\n\nexport const toOutputFilePathInCss: typeof toOutputFilePathWithoutRuntime =","sourceCodeStart":1701,"sourceCodeEnd":1737,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/build.ts#L1701-L1737","documentation":"experimental.renderBuiltUrl can return { runtime: '...' } to emit a runtime-resolved URL, but only for references inside JS modules. toOutputFilePathWithoutRuntime (also aliased for CSS and HTML) rejects a runtime result for asset/public files referenced from css or html hosts because those hosts have no runtime expression channel.","triggerScenarios":"Implementing experimental.renderBuiltUrl and returning { runtime: 'import.meta...' } for a filename whose hostType is 'css' or 'html' (i.e. url() in CSS or <script>/<link> in HTML).","commonSituations":"Custom asset-URL rewriting plugins ported from a JS-only context; trying to make HTML/CSS references use import.meta.url which does not exist there.","solutions":["For css/html hosts, return a plain string URL or { relative: boolean } from renderBuiltUrl instead of { runtime }.","Branch on the hostType argument passed to renderBuiltUrl and only return runtime for hostType === 'js'.","Move the asset reference into JS so runtime resolution is available."],"exampleFix":"// before\nrenderBuiltUrl: (filename, { hostType }) => ({ runtime: `new URL(${JSON.stringify(filename)}, import.meta.url)` })\n// after\nrenderBuiltUrl: (filename, { hostType }) =>\n  hostType === 'js'\n    ? { runtime: `new URL(${JSON.stringify(filename)}, import.meta.url)` }\n    : filename","handlingStrategy":"validation","validationCode":"function safeRenderBuiltUrl(fn) {\n  return (filename, ctx) => {\n    const r = fn(filename, ctx);\n    if (r && typeof r === 'object' && r.runtime && ctx.hostType !== 'js') {\n      return filename; // downgrade non-JS hosts to plain string\n    }\n    return r;\n  };\n}","typeGuard":"function isRuntimeResult(r, hostType) {\n  return Boolean(r && typeof r === 'object' && 'runtime' in r && hostType === 'js');\n}","tryCatchPattern":null,"preventionTips":["Branch experimental.renderBuiltUrl on hostType; only return { runtime } for JS.","Return plain strings or { relative } for css/html references."],"tags":["build","assets","experimental","render-built-url"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}