Skip to content

Subtle change in Vite runtime stacktrace with prepareStackTrace since 5.1.5 #16178

Closed
@hi-ogawa

Description

@hi-ogawa

Describe the bug

While upgrading Vite from 5.1.0 to 5.1.6 on my monorepo with vite-node-miniflare hi-ogawa/vite-plugins#198, I found my tests which asserts stacktrace are failing. On further investigation, there seems to be a subtle difference since 5.1.5 as seen in this simpler reproduction.

node run.mjs ./repro-entry.ts
...
Error: crash ssr
    at crash (.../repro-entry.ts:2:9)
    at main (.../repro-entry.ts:6:9)  <---- 6:3 became 6:9 since 5.1.5
function crash(message) {
  throw new Error(message);
}

function main() {
  crash("crash ssr");
//^ 6:3        <- before
//      ^ 6:9  <- after
}

main();

On my actual case, I use a plugin vitePluginSimpleHmr which adds one more transform to ssr code, then stacktrace seems more broken (not only column, but also line and absolute path resolution is not working). For this part, there might be an issue with my plugin, so I'm not sure whether it's related to Vite side change and I haven't tried minimal repro for that yet.

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/vite-runtime-stacktrace-5.1.5

Steps to reproduce

In the reproduction, I added a comparison with node and also when vite entry is plain javascript, in which case there's no difference in stacktrace.

Stackblitz doesn't seem to have a good support on stacktrace, so it might be necessary to copy the reproduction locally. To skip cloning the entire repo, you can use tools such as https://github.com/tiged/tiged

npx tiged hi-ogawa/reproductions/vite-runtime-stacktrace-5.1.5 repro

System Info

  System:
    OS: Linux 6.7 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5625U with Radeon Graphics
    Memory: 9.30 GB / 14.98 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 20.11.1 - ~/.volta/tools/image/node/20.11.1/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 10.2.4 - ~/.volta/tools/image/node/20.11.1/bin/npm
    pnpm: 8.12.0 - ~/.volta/bin/pnpm
    bun: 1.0.26 - ~/.volta/bin/bun
  Browsers:
    Chromium: 122.0.6261.111
  npmPackages:
    vite: 5.1.5 => 5.1.5

Used Package Manager

npm

Logs

This is the same content as reproduction readme, but just in case:

# node
node ./repro-entry.mjs
...
Error: crash ssr
    at crash (.../repro-entry.mjs:2:9)
    at main (.../repro-entry.mjs:6:3)
    ...


# vite + js
node run.mjs ./repro-entry.mjs
...
Error: crash ssr
    at crash (.../repro-entry.mjs:2:9)
    at main (.../repro-entry.mjs:6:3)
    ...


# vite 5.1.4 + ts
node run.mjs ./repro-entry.ts
...
Error: crash ssr
    at crash (.../repro-entry.ts:2:9)
    at main (.../repro-entry.ts:6:3)
    ...


# vite 5.1.5 + ts
node run.mjs ./repro-entry.ts
...
Error: crash ssr
    at crash (.../repro-entry.ts:2:9)
    at main (.../repro-entry.ts:6:9)  <---- 6:3 became 6:9

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: sourcemapSourcemap supportp3-minor-bugAn edge case that only affects very specific usage (priority)regressionThe issue only appears after a new release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions