kit
kit copied to clipboard
report better error location in stack trace
Describe the problem
If there's an error in a route - now that the filenames themselves are not descriptive (e.g. +page.svelte) it is sometimes hard to figure out where the problem is ..
e.g.
Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
at +page.svelte:27:22
at Object.$$render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1771:22)
at Object.default (root.svelte:41:38)
at eval (/src/routes/+layout.svelte:19:141)
at Object.$$render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1771:22)
....
because I have a lot of +page.svelte pages I don't know which one it means.
Describe the proposed solution
Provide a fuller path of the file . .e.g
Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
at /routes/users/+page.svelte:27:22
Alternatives considered
No response
Importance
would make my life easier
Additional Information
No response
Please provide a reproduction
- be me
- create new svelte kit skeleton app
- add this to the route +page.svelte
<script>
const o = null
console.log(o.length)
</script>
result
Cannot read properties of null (reading 'length')
TypeError: Cannot read properties of null (reading 'length')
at +page.svelte:5:18
at Object.$$render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1771:22)
at Object.default (root.svelte:41:38)
at eval (/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/components/layout.svelte:8:41)
at Object.$$render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1771:22)
at root.svelte:40:37
at $$render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1771:22)
at Object.render (/node_modules/.pnpm/[email protected]/node_modules/svelte/internal/index.mjs:1779:26)
at render_response (file:///Users/jonahfox/sandpit/my-app/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:121:27)
at async render_page (file:///Users/jonahfox/sandpit/my-app/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:276:10)
Is that OK - or do you need an actual repo ?
Yep, that works, thanks. The problem is coming from this line in Vite...
const source = `${pos.source}:${pos.line}:${pos.column}`
...because pos.source is just +page.svelte instead of e.g. /src/routes/+page.svelte. Ideally I think pos.source should be resolved against url if it's relative. Will try and create a minimal Vite repro (i.e. no SvelteKit) and raise an issue at some point if no-one beats me to it.
closing this as Vite now prints the absolute path since https://github.com/vitejs/vite/commit/88c855eadcff7b59e175610c0f8a0b1e04a3ad12