diff --git a/.changeset/four-ligers-help.md b/.changeset/four-ligers-help.md new file mode 100644 index 000000000000..e9973f1b87c0 --- /dev/null +++ b/.changeset/four-ligers-help.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] load errorTemplate from correct location diff --git a/packages/kit/src/core/config/index.js b/packages/kit/src/core/config/index.js index 39f4160cdac0..eac24207466e 100644 --- a/packages/kit/src/core/config/index.js +++ b/packages/kit/src/core/config/index.js @@ -43,7 +43,14 @@ export function load_template(cwd, config) { * @param {import('types').ValidatedConfig} config */ export function load_error_page(config) { - const { errorTemplate } = config.kit.files; + let { errorTemplate } = config.kit.files; + + // Don't do this inside resolving the config, because that would mean + // adding/removing error.html isn't detected and would require a restart. + if (!fs.existsSync(config.kit.files.errorTemplate)) { + errorTemplate = url.fileURLToPath(new URL('./default-error.html', import.meta.url)); + } + return fs.readFileSync(errorTemplate, 'utf-8'); } @@ -86,12 +93,6 @@ function process_config(config, { cwd = process.cwd() } = {}) { } } - if (!fs.existsSync(validated.kit.files.errorTemplate)) { - validated.kit.files.errorTemplate = url.fileURLToPath( - new URL('./default-error.html', import.meta.url) - ); - } - return validated; }