{"record":{"id":"442b9f72acee55a7","repo":"withastro/astro","slug":"script-src-src-references-an-asset-in-the","errorCode":null,"errorMessage":"\n\n<script src=\"${src}\"> references an asset in the \"${publicDir}\" directory. Please add the \"is:inline\" directive to keep this asset from being bundled.\n\nFile: ${id}","messagePattern":"\n\n<script src=\"(.+?)\"> references an asset in the \"(.+?)\" directory\\. Please add the \"is:inline\" directive to keep this asset from being bundled\\.\n\nFile: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/vite-plugin-astro/index.ts","lineNumber":213,"sourceCode":"\t\t\t\t\t\t\t// SSR script only exists to make them appear in the module graph.\n\t\t\t\t\t\t\tif (isAstroServerEnvironment(this.environment)) {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tcode: `/* client script, empty in SSR: ${id} */`,\n\t\t\t\t\t\t\t\t\tmoduleType: 'ts',\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst script = compileMetadata.scripts[query.index];\n\t\t\t\t\t\t\tif (!script) {\n\t\t\t\t\t\t\t\tthrow new Error(`No script at index ${query.index}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (script.type === 'external') {\n\t\t\t\t\t\t\t\tconst src = script.src!;\n\t\t\t\t\t\t\t\tif (src.startsWith('/') && !isBrowserPath(src)) {\n\t\t\t\t\t\t\t\t\tconst publicDir =\n\t\t\t\t\t\t\t\t\t\tconfig.publicDir.pathname.replace(/\\/$/, '').split('/').pop() + '/';\n\t\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t\t`\\n\\n<script src=\"${src}\"> references an asset in the \"${publicDir}\" directory. Please add the \"is:inline\" directive to keep this asset from being bundled.\\n\\nFile: ${id}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst result: vite.Rolldown.SourceDescription = {\n\t\t\t\t\t\t\t\tcode: '',\n\t\t\t\t\t\t\t\tmoduleType: 'ts',\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tvite: {\n\t\t\t\t\t\t\t\t\t\tlang: 'ts',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tswitch (script.type) {\n\t\t\t\t\t\t\t\tcase 'inline': {\n\t\t\t\t\t\t\t\t\tresult.code = script.code ?? '';","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/vite-plugin-astro/index.ts#L195-L231","documentation":"Thrown by the Astro Vite plugin when a `<script src=\"/...\">` in a `.astro` component points at a file inside the configured `publicDir` (default `public/`). Astro tries to bundle external script references, but files in `public/` are served as-is and must not be processed by the bundler. The fix is to mark the script `is:inline` so Astro leaves it untouched.","triggerScenarios":"Writing `<script src=\"/lib/analytics.js\">` where `public/lib/analytics.js` exists. The plugin detects `src.startsWith('/') && !isBrowserPath(src)` and derives the publicDir name from `config.publicDir`. Any absolute `/...` script whose target lives under public triggers it.","commonSituations":"Adding a third-party script (analytics, widgets) by dropping the file into `public/` and referencing it from a layout. Migrating from plain HTML where `<script src>` worked without bundler awareness. Forgetting `is:inline` on scripts that should bypass Vite.","solutions":["Add `is:inline` to the script tag: `<script is:inline src=\"/lib/analytics.js\">`.","Alternatively, move the file out of `public/` into `src/` and import it as a module so Astro can bundle it.","If the script is a remote URL (https://), it is not affected — only absolute local paths starting with `/` are checked."],"exampleFix":"<!-- before -->\n<script src=\"/lib/analytics.js\"></script>\n\n<!-- after -->\n<script is:inline src=\"/lib/analytics.js\"></script>","handlingStrategy":"validation","validationCode":"// In your .astro file, before referencing a public asset script:\nconst isPublicAsset = (src) => src.startsWith('/') && !src.startsWith('//');\n// If true, always render with is:inline.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always add is:inline to scripts that reference /public assets.","Keep third-party vendor scripts in public/ and reference them with is:inline.","For bundleable scripts, place them under src/ and import them instead of using src=."],"tags":["astro-component","scripts","bundler","public-dir"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}