Source map line numbers are wrong when using typescript
See original GitHub issueDescribe the bug When using typescript within .svelte files, the generated source map references the wrong line number, it is too low.
To Reproduce
- Checkout the template and install libraries:
npx degit sveltejs/template svelte-typescript-app
cd svelte-typescript-app
npm install
- Modify the script in
src/App.svelte
like this:
<script>
export let name;
// test comment
console.error("error logged from line five in App.svelte")
</script>
- Run the app and visit it in a browser, the following message is in the JavaScript console:
error logged from line five in App.svelte App.svelte:5
- Now add TypeScript support according to the instructions in the blog:
node scripts/setupTypeScript.js
npm install
- Mark the script in
src/App.svelte
as TypeScript:
<script lang="ts">
export let name;
// test comment
console.error("error logged from line five in App.svelte")
</script>
- Run the app, visit it again, find the following message in the browser console:
error logged from line five in App.svelte App.svelte:3
- Clicking on the file name takes me to line 3 of
App.svelte
:
I’ve published a reproduction repo here: https://github.com/fd0/svelte-bug-typescript-sourcemap (including package-lock.json
).
Expected behavior
The error message should refer to the correct line in the source code (line 5 instead of line 3).
Information about your Svelte project:
- Chrome 83.0.4103.116
- Debian Buster
- Svelte 3.24.0
- Rollup 2.22.2
Severity
It’s very annoying, but does not block me (or anybody else). Debugging takes much longer.
Additional context
Thank you very much for adding TypeScript to Svelte, I love it!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:19 (14 by maintainers)
Top Results From Across the Web
Incorrect line numbers - sourcemaps, Webpack 2 Typescript
I have been doing a lot of research on trying to get correct line numbers for my Typescript source code using Webpack 2.2.1...
Read more >source-map-support - npm
It uses the source-map module to replace the paths and line numbers of source-mapped files with their original paths and line numbers.
Read more >What is wrong with SOURCE MAPS and how not to mess with ...
The remaining 4 numbers are the column number in the corresponding line of the generated file, the source number, the source line number...
Read more >Source map line numbers mismatch (Angular) - Elastic Discuss
I am using Angular 9 and elastic/apm-rum-angular version 1.1.6. I uploaded the source maps generated by running "ng build --source-map".
Read more >Incorrect Line Numbers - Sourcemaps, Webpack 2 ... - ADocLib
Returning an object with the generated code source map and AST. boolean | false | Attempt to use the same line numbers in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@milahu this sounds like a bug in either Vite (e.g. this plugin) or
@rollup/plugin-alias
. It’d be great if you were able to narrow down which project is causing it! Thanks as always for your help improving source map support!still an issue with import alias this should also affect svelte-kit where import alias is used by default
repro
errors start at line 50
src/components/apps/WallpaperApp/Wallpaper.svelte
relevant config …
vite.config.ts
tsconfig.json
i tried to patch alias imports to relative imports with https://stackoverflow.com/questions/57188027/refactor-aliased-imports-to-relative-paths but jscodeshift cannot parse *.svelte files