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

fix(config): make stacktrace path correct when sourcemap is enabled #18833

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

Description

fixes #18832

@sapphi-red sapphi-red added the p2-edge-case Bug, but has workaround or limited in scope (priority) label Nov 29, 2024
bluwy
bluwy previously approved these changes Nov 29, 2024
hi-ogawa
hi-ogawa previously approved these changes Dec 1, 2024
Copy link

pkg-pr-new bot commented Dec 1, 2024

Open in Stackblitz

npm i https://pkg.pr.new/vite@18833

commit: 7000908

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Dec 1, 2024

I just veririfed the reproduction is fixed with pkg.pr.new, but for local playground, there's something odd regardless of NODE_OPTIONS. I added console.trace("test") and this is the log.

$ pnpm -C playground/html dev

> @vitejs/[email protected] dev /home/hiroshi/code/others/vite/playground/html
> vite

Trace: test
    at file:///home/hiroshi/code/others/vite/playground/html/node_modules/.vite-temp/file:/home/hiroshi/code/others/vite/playground/html/vite.config.js:4:9
    ...

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Dec 1, 2024

Oh, it looks like source-map-support is breaking the stack when using cli locally

if (!import.meta.url.includes('node_modules')) {
try {
// only available as dev dependency
await import('source-map-support').then((r) => r.default.install())
} catch {}
}

Can this be maybe changed to process.setSourceMapsEnabled(true)?

@sapphi-red sapphi-red dismissed stale reviews from hi-ogawa and bluwy via 7000908 December 2, 2024 08:02
@sapphi-red
Copy link
Member Author

I removed the pathToFileURL part as it seems it works without it. This should fix users that are enabling source-map-support before config load.

@sapphi-red
Copy link
Member Author

Can this be maybe changed to process.setSourceMapsEnabled(true)?

Ah, yeah, maybe we can migrate to it in a separate PR.

Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@@ -1720,6 +1720,8 @@ async function bundleConfigFile(
format: isESM ? 'esm' : 'cjs',
mainFields: ['main'],
sourcemap: 'inline',
// the last slash is needed to make the path correct
sourceRoot: path.dirname(fileName) + '/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourceRoot: path.dirname(fileName) + '/',
sourceRoot: path.dirname(fileName) + path.sep,

Should this use path.sep since it could be backward slash now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vite 6 config's source map file reference is off
3 participants