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(vite-node): fix source map of inlined node_modules #7557

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Feb 25, 2025

Description

Related

Currently ssr transform tries to preserve lines by best effort vitejs/vite#19004, but this is not guaranteed since user plugin can also change lines and also there are some not-so-edge cases ssr transform has't handle it yet (I added it as a test case).

Considering Vite SSR / module runner is also injecting source map (regardless of user code or inlined deps), I think we should allow this for Vitest / vite-node as well.

Also as an important context, preserving lines for transform is hard for the ecosystem for the following aspects:

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Feb 25, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8f7b281
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/67bd5ab7876b3a00085f930a
😎 Deploy Preview https://deploy-preview-7557--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -0,0 +1,11 @@
import 'node:path'

export function testStack() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently ssr transform doesn't preserve lines with export, so this repro fails on main.

@@ -428,7 +428,7 @@ export class ViteNodeServer {
}

const sourcemap = this.options.sourcemap ?? 'inline'
if (sourcemap === 'inline' && result && !id.includes('node_modules')) {
if (sourcemap === 'inline' && result) {
Copy link
Member

Choose a reason for hiding this comment

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

I think similar change was proposed before:

We don't inline source map because it's expensive to do for every file in node modules

Copy link
Contributor Author

@hi-ogawa hi-ogawa Feb 25, 2025

Choose a reason for hiding this comment

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

Yes, we can make it to opt-in (like #7095) if broken debugger and stacktrace for inlined deps are acceptable by default, but I'm leaning towards just aligning with Vite SSR.

Copy link
Member

@sheremet-va sheremet-va Feb 25, 2025

Choose a reason for hiding this comment

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

Yes, we had a discussion with the rolldown team not so long ago and decided to remove this check after all

@hi-ogawa
Copy link
Contributor Author

New test is not running on CI due to #7558. We need to merge that first.

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

Successfully merging this pull request may close these issues.

3 participants