Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages/*/CHANGELOG.md
packages/vite/src/node/ssr/__tests__/fixtures/errors/syntax-error.*
packages/vite/src/node/ssr/runtime/__tests__/fixtures/esm-external-column-test/index.mjs
playground-temp/
dist/
LICENSE.md
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { outer } from '@vitejs/esm-external-column-test'

function userFn() {
throw new Error('column test error')
}

outer(userFn)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var _padding_______________________; export function outer(fn) { return inner(fn); } function inner(fn) { return fn(); }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@vitejs/esm-external-column-test",
"private": true,
"type": "module",
"version": "0.0.0",
"main": "index.mjs"
}
1 change: 1 addition & 0 deletions packages/vite/src/node/ssr/runtime/__tests__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@vitejs/cjs-external": "link:./fixtures/cjs-external",
"@vitejs/esm-external": "link:./fixtures/esm-external",
"@vitejs/esm-external-column-test": "link:./fixtures/esm-external-column-test",
"tinyspy": "2.2.0",
"birpc": "^0.2.19"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,40 @@ describe('module runner initialization', async () => {
]
`)
})

it('esm external stack traces should have correct column numbers', async ({
runner,
}) => {
const error = await getError(() =>
runner.import('/fixtures/esm-external-column-test.js'),
)
const stack = error.stack!.split('\n')
const innerFrame = stack.find((line) => line.includes('inner'))
const outerFrame = stack.find((line) => line.includes('outer'))

// This test verifies the fix for #21561 where ESM external modules had incorrect
// column numbers due to an erroneous 62-character offset being subtracted.
// The ESM external module has code on a single line with padding:
// "var _padding...; export function outer(fn) { return inner(fn); } function inner(fn) { return fn(); }"
//
// With the bug (subtracting 62), columns would be around 11 and 52.
// With the fix (no subtraction), columns should be in a reasonable range (> 60).
expect(innerFrame).toBeDefined()
expect(outerFrame).toBeDefined()

// Extract column numbers from stack frames like ":1:114)"
const innerMatch = innerFrame!.match(/:(\d+):(\d+)\)/)
const outerMatch = outerFrame!.match(/:(\d+):(\d+)\)/)

expect(innerMatch).toBeDefined()
expect(outerMatch).toBeDefined()

const innerCol = parseInt(innerMatch![2])
const outerCol = parseInt(outerMatch![2])

// Both columns should be > 60 (with the old bug, they would be around 11 and 52)
// This verifies the 62-character offset is NOT being incorrectly applied
expect(innerCol).toBeGreaterThan(60)
expect(outerCol).toBeGreaterThan(60)
})
})
6 changes: 5 additions & 1 deletion packages/vite/src/node/ssr/runtime/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export async function createModuleRunnerTester(
ws: false,
},
ssr: {
external: ['@vitejs/cjs-external', '@vitejs/esm-external'],
external: [
'@vitejs/cjs-external',
'@vitejs/esm-external',
'@vitejs/esm-external-column-test',
],
},
optimizeDeps: {
disabled: true,
Expand Down
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.