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

SSR transform drops map.sources when multiple sources #17676

Closed
7 tasks done
AriPerkkio opened this issue Jul 14, 2024 · 0 comments · Fixed by #17677
Closed
7 tasks done

SSR transform drops map.sources when multiple sources #17676

AriPerkkio opened this issue Jul 14, 2024 · 0 comments · Fixed by #17677

Comments

@AriPerkkio
Copy link
Contributor

AriPerkkio commented Jul 14, 2024

Describe the bug

When Vite SSR transforms file that has source map with multiple sources, only a single entry is returned in the final source map's sources. This causes issues in Vitest: vitest-dev/vitest#6120

With source map like

{
  "version": 3,
  "file": "bundle.js",
  "sources": [
    "./first.ts",
    "./second.ts"
  ],
  "sourcesContent": [
    "...",
    "..."
  ],
  "names": [
    "covered",
    "uncovered"
  ],
  "mappings": "..."
}

... Vite returns map with sources: ["./first.ts"]. The "./second.ts" is dropped during SSR transform.

Reproduction

https://stackblitz.com/~/edit/vitejs-vite-fj3cj8

Steps to reproduce

pnpm install
pnpm run build # Create a bundle with Rollup
pnpm run start # Calls "node ./server.mjs" which runs Vite via Node API
const ssr = await server.transformRequest("./dist/bundle.js", { ssr: true });
const web = await server.transformRequest("./dist/bundle.js", { ssr: false });

console.log({ ssr: ssr.map.sources, web: web.map.sources });
{
  ssr: [ '../src/first.ts' ], // <-- Missing '../src/second.ts'
  web: [ '../src/first.ts', '../src/second.ts' ]
}

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 74.52 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.15.0/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
    pnpm: 9.4.0 - ~/.nvm/versions/node/v20.15.0/bin/pnpm
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    @vitejs/release-scripts: ^1.3.1 => 1.3.1 
    rollup: ^4.13.0 => 4.13.0 
    vite: workspace:* => 5.3.3

Used Package Manager

pnpm

Logs

No response

Validations

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

Successfully merging a pull request may close this issue.

1 participant