I am using Svelte 4 with
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"svelte": "^4.2.7",
When I run the app using:
npm run dev
which calls vite dev
underneath
and try to access an invalid URL like http://localhost:5173//
I get a good error screen:
corresponding to routes/+error.svelte
. But if I run the app using:
npm run preview
which calls vite preview
underneath
this is what I get:
TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:637:13)
at file:///Users/xxx/xxx/node_modules/@sveltejs/kit/src/exports/vite/preview/index.js:86:33
at call (file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:43000:7)
at next (file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:42944:5)
at /Users/xxx/xxx/node_modules/sirv/build.js:180:28
at call (file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:43000:7)
at next (file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:42944:5)
at file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:54650:28
at viteAssetMiddleware (file:///Users/xxx/xxx/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:69268:7)
I am not posting a screenshot but this error gets echoed to the UI (i.e., printed in the web browser). How can I avoid this and get same behavior as with npm run dev
?