{"record":{"id":"900d18008580f2fa","repo":"sveltejs/kit","slug":"cannot-use-prerendering-if-page-template-contains","errorCode":null,"errorMessage":"Cannot use prerendering if page template contains %sveltekit.nonce%","messagePattern":"Cannot use prerendering if page template contains (.+?)veltekit\\.nonce%","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/server/page/render.js","lineNumber":69,"sourceCode":"\tbranch,\n\tfetched,\n\tpage_config,\n\tstatus,\n\terror = null,\n\tevent,\n\tstate,\n\tresolve_opts,\n\taction_result,\n\tdata_serializer,\n\terror_components\n}) {\n\tif (state.prerendering || state.prerender_default === true) {\n\t\tif (options.csp.mode === 'nonce') {\n\t\t\tthrow new Error('Cannot use prerendering if config.csp.mode === \"nonce\"');\n\t\t}\n\n\t\tif (options.app_template_contains_nonce) {\n\t\t\tthrow new Error('Cannot use prerendering if page template contains %sveltekit.nonce%');\n\t\t}\n\t}\n\n\tconst client = manifest.client;\n\n\tconst modulepreloads = new Set(client?.imports);\n\tconst stylesheets = new Set(client?.stylesheets);\n\n\t/** @type {Map<string, import('types').FontDependency>} */\n\tconst fonts = new Map(client?.fonts.map((font) => [font.file, font]));\n\n\t/**\n\t * The value of the Link header that is added to the response when not prerendering\n\t * @type {Set<string>}\n\t */\n\tconst link_headers = new Set();\n\n\t/** @type {Map<string, string>} */","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/page/render.js#L51-L87","documentation":"The prerendered app template must not contain the literal `%sveltekit.nonce%` placeholder, because static HTML cannot substitute a per-request nonce. SvelteKit detects that the template includes the nonce placeholder while prerendering and throws.","triggerScenarios":"Prerendering is active (state.prerendering or prerender_default === true) and `options.app_template_contains_nonce` is true, i.e. `src/app.html` contains the string `%sveltekit.nonce%`.","commonSituations":"Manually adding `%sveltekit.nonce%` to app.html for custom CSP handling while some pages are prerendered; upgrading SvelteKit where the template placeholder requirement changed and an old custom app.html still contains it.","solutions":["Remove `%sveltekit.nonce%` from src/app.html and let SvelteKit inject CSP directives automatically","Disable prerendering on pages that need the nonce placeholder","Switch CSP mode to 'hash' so a nonce placeholder is unnecessary"],"exampleFix":"<!-- before: src/app.html -->\n<script nonce=\"%sveltekit.nonce%\">...</script>\n<!-- after -->\n%%sveltekit.head%%","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nconst ok = !readFileSync('src/app.html', 'utf8').includes('%sveltekit.nonce%');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not put %sveltekit.nonce% in app.html when prerendering any page","Re-check custom app.html after SvelteKit upgrades","Use hash-mode CSP to avoid nonce placeholders entirely"],"tags":["csp","prerendering","app-html"],"backgroundTag":"csp-nonce-prerender-conflict","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}