sveltejs / svelte · Issue No. 18778
I am referring to my previous issue #18491, which was closed by #18518. The problem is still there in the latest version (5.57.0). I tried to follow the explanation of the PR and played with adding source and file in various forms and I couldn't get it working. I tried to inspect the variables in node_modules/svelte/src/compiler/utils/mapped_code.js inside the function combine_sourcemaps and checking conditions, reversing orders, etc. but I couldn't find the root cause.
Since the reproduction can't work in the REPL, and since it is fairly small, I'll provide the files here.
Start from the svelte template in npm create vite@latest, install magic-string, and edit only these two files:
vite.config.js
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import MagicString from 'magic-string'
// https://vite.dev/config/
export default defineConfig({
plugins: [
{
name: "tst",
transform(code, id) {
if (!id.includes('App.svelte')) {
return
}
const m = new MagicString(code)
m.appendRight(10, 'let leben = 42\n\n')
return {
code: m.toString(),
map: m.generateMap(/* add {file: id}, {source: id}, {file: 'App.svelte'}, etc */),
}
},
},
svelte()
],
})
App.svelte
<script>
console.error('helo')
</script>
Hello, see devtools
Then run it, go to devtools, and look at the location of the console.error message, it will be at the beginning of the script block, not at the actual location.
Not relevant
System:
OS: Linux 7.0 Ubuntu 26.04 LTS 26.04 LTS (Resolute Raccoon)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1195G7 @ 2.90GHz
Memory: 10.74 GB / 15.27 GB
Container: Yes
Shell: 5.3.9 - /bin/bash
Binaries:
Node: 24.19.0 - /home/k1dv5/.local/bin/node
npm: 11.17.0 - /home/k1dv5/.local/bin/npm
Browsers:
Firefox: 154.0.1
Firefox Developer Edition: 154.0.1
npmPackages:
svelte: ^5.57.0 => 5.57.0
annoyance
Relay reads this issue against the repository's contribution signals: the files it is likely to touch, how the maintainers triage work this size, and what the first contribution would exercise.
The full analysis for this issue is still being assembled. Until then, the description above and the thread on GitHub are the most reliable context.