From edc6cf9066871d19ce1e60ed4a925d875f84e2b8 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 7 Jul 2023 07:40:32 +0545 Subject: [PATCH 1/3] feat: better error message for preview if build output doesn't exist --- .changeset/shy-colts-sniff.md | 5 +++++ packages/kit/src/exports/vite/preview/index.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/shy-colts-sniff.md diff --git a/.changeset/shy-colts-sniff.md b/.changeset/shy-colts-sniff.md new file mode 100644 index 000000000000..2a9dcdf60567 --- /dev/null +++ b/.changeset/shy-colts-sniff.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +feat: more helpful error for preview if build output doesn't exist diff --git a/packages/kit/src/exports/vite/preview/index.js b/packages/kit/src/exports/vite/preview/index.js index 326818c3b181..41dc0d6f5c10 100644 --- a/packages/kit/src/exports/vite/preview/index.js +++ b/packages/kit/src/exports/vite/preview/index.js @@ -1,4 +1,4 @@ -import fs from 'node:fs'; +import fs, { existsSync } from 'node:fs'; import { join } from 'node:path'; import { pathToFileURL } from 'node:url'; import sirv from 'sirv'; @@ -36,6 +36,10 @@ export async function preview(vite, vite_config, svelte_config) { const dir = join(svelte_config.kit.outDir, 'output/server'); + if (!existsSync(dir)) { + throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`) + } + /** @type {import('types').ServerInternalModule} */ const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href); From f33e4e63b053cfd59ab9bc7215e9c265f3ae3e85 Mon Sep 17 00:00:00 2001 From: gtmnayan Date: Fri, 7 Jul 2023 07:41:48 +0545 Subject: [PATCH 2/3] format --- packages/kit/src/exports/vite/preview/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/exports/vite/preview/index.js b/packages/kit/src/exports/vite/preview/index.js index 41dc0d6f5c10..3573369d3912 100644 --- a/packages/kit/src/exports/vite/preview/index.js +++ b/packages/kit/src/exports/vite/preview/index.js @@ -37,7 +37,7 @@ export async function preview(vite, vite_config, svelte_config) { const dir = join(svelte_config.kit.outDir, 'output/server'); if (!existsSync(dir)) { - throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`) + throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`); } /** @type {import('types').ServerInternalModule} */ From e19ceb8650c4ed62e8a4f15e8b1cb4a182df5511 Mon Sep 17 00:00:00 2001 From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:34:38 +0545 Subject: [PATCH 3/3] replace existsSync with fs.existsSync Co-authored-by: Conduitry --- packages/kit/src/exports/vite/preview/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/exports/vite/preview/index.js b/packages/kit/src/exports/vite/preview/index.js index 3573369d3912..1e5045dd3bda 100644 --- a/packages/kit/src/exports/vite/preview/index.js +++ b/packages/kit/src/exports/vite/preview/index.js @@ -1,4 +1,4 @@ -import fs, { existsSync } from 'node:fs'; +import fs from 'node:fs'; import { join } from 'node:path'; import { pathToFileURL } from 'node:url'; import sirv from 'sirv'; @@ -36,7 +36,7 @@ export async function preview(vite, vite_config, svelte_config) { const dir = join(svelte_config.kit.outDir, 'output/server'); - if (!existsSync(dir)) { + if (!fs.existsSync(dir)) { throw new Error(`Server files not found at ${dir}, did you run \`build\` first?`); }