-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Broken source maps for bundles with packages from node_modules #6526
Comments
For the bug to trigger it seems to be essential to have a package from node_modules in the bundle. Just bundling two local source files together does not repro the bug |
After doing a dump with |
This looks similar to #5523. Workaround is to prevent Vitest/Vite from processing already bundled // pkg-b/vitest.config.ts
import { defineConfig } from "vitest/config"
export default defineConfig({
test: {
server: {
deps: {
external: [/pkg-a/],
}
}
}
}) With this config, I see this error on Vitest:
|
Looks like bug in Vite.
I renamed When we request the vitest/packages/vite-node/src/server.ts Line 411 in 2a50464
console.log(result.map.sources);
> {
> "sources": [
> "../node_modules/.pnpm/base32-decode@1.0.0/node_modules/node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js",
> "../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/pkg-a-entrypoint.js"
> ],
> ...
> } Minimal repro without Vitest: import { createServer } from "vite";
const server = await createServer();
await server.listen();
const ssrResult = await server.transformRequest(
"/Users/x/vitest-sourcemap-bug/pkg-a/dist.js",
{ ssr: true }
);
console.log(ssrResult.map);
/*
sources: [
'../node_modules/.pnpm/base32-decode@1.0.0/node_modules/node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js',
'../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/pkg-a-entrypoint.js'
],
file: '/Users/x/vitest-sourcemap-bug/pkg-a/dist.js'
*/
// Without SSR:
const webResult = await server.transformRequest(
"/Users/x/vitest-sourcemap-bug/pkg-a/dist.js",
{ ssr: false }
);
console.log(webResult.map);
/*
sources: [
'../node_modules/.pnpm/base32-decode@1.0.0/node_modules/base32-decode/index.js',
'pkg-a-entrypoint.js'
],
*/
server.close(); If I manually fix the path in FAIL index.test.js > repro
Error: Test error
❯ Module.foo ../pkg-a/pkg-a-entrypoint.js:5:9
❯ index.test.js:5:3
3|
4| test("repro", () => {
5| foo();
| ^
6| });
7| I'll create upstream bug for this. |
I just ran into this yesterday, and this bug is very timely! |
Describe the bug
I have a workspace with two packages:
pkg-a
build a bundle of its own code and packages from node_modulespkg-b
runs test from vitest that import code frompkg-a
The sourcemaps for errors thrown from inside
pkg-a
report incorrect source locations:Running similar code in node JS produces the correct stack trace:
Reproduction
https://github.com/dmaretskyi/vitest-sourcemap-bug
See README for repro steps
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: