parcel icon indicating copy to clipboard operation
parcel copied to clipboard

Invalid sourcemaps with template literal

Open mischnic opened this issue 1 year ago • 3 comments

After some heavy debugging I figured out. If you are using Template literals (``) the source map is completely broken.

index.ts

 console.log("test1") // line 1 correct

let text = `
    1
    1
    1
    1
    1
    1
    `

console.log("test2") // this should be line 12, instead 17 in devtools

let test0
let test1

console.log("test3")  // this only woks because last line if you add more content it wont work

index.html

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<script src="./index.ts"></script>
	</body>
</html>

Devtools image

Originally posted by @Levminer in https://github.com/parcel-bundler/parcel/issues/5815#issuecomment-1181540189

mischnic avatar Jul 12 '22 12:07 mischnic

When using Windows line endings (cr + lf), the sourcemaps are wrong:

Bildschirmfoto 2022-07-12 um 14 23 43

mischnic avatar Jul 12 '22 12:07 mischnic

As a workaround setting line endings LF in vs code fixes this, thanks for the help!

Levminer avatar Jul 12 '22 13:07 Levminer

Thanks, God, I found this issue! 😀 Was struggling with weird debugging issues and totally wrong source maps... Changing CRLF to LF line endings is a workaround, but this should really be fixed.

mm-dsibinski avatar Sep 14 '22 10:09 mm-dsibinski