Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect stack traces with inline sourceMaps #861

Open
maxfliri opened this issue Oct 24, 2024 · 1 comment
Open

Incorrect stack traces with inline sourceMaps #861

maxfliri opened this issue Oct 24, 2024 · 1 comment

Comments

@maxfliri
Copy link

With swc-node v1.10.9, stack traces report incorrect line numbers when swc is configured to generate inline sourceMaps.

This happens with SWCRC=true when .swcrc has "sourceMaps": "inline". It also happens always when running without SWCRC=true, because this always results in inline sourceMaps, as reported in #848.

I get correct stack traces only when I use SWCRC=true and .swcrc has "sourceMaps": true.

@maxfliri
Copy link
Author

I think the reason might be that sourcemaps are not added to SourcemapMap when inline.

Sourcemaps are added to SourcemapMap in the function below, which handles non-inline sourcemaps. As far as I can this is not happening for inline sourcemaps.

const injectInlineSourceMap = ({
filename,
code,
map,
}: {
filename: string
code: string
map: string | undefined
}): string => {
if (map) {
SourcemapMap.set(filename, map)
const base64Map = Buffer.from(map, 'utf8').toString('base64')
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`
return `${code}\n${sourceMapContent}`
}
return code
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant