Skip to content

fix(ssr): handle uninitialized export access as undefined#19959

Merged
patak-cat merged 5 commits intovitejs:mainfrom
hi-ogawa:fix-tolerate-no-init-as-undefined
May 2, 2025
Merged

fix(ssr): handle uninitialized export access as undefined#19959
patak-cat merged 5 commits intovitejs:mainfrom
hi-ogawa:fix-tolerate-no-init-as-undefined

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Apr 29, 2025

Description

Export hoisting #18983 made an cyclic import handling to match better with esm (meaning valid cyclic imports are accepted and invalid ones are correctly rejected), but it turns out to be too strict for Vitest users which tends to import arbitrary files as first entry. The behavior change was too drastic for the patch release 6.3.3 at least, so in this PR, I added try/catch to make invalid exports to be fallback to undefined. Note that this should still make valid cyclic imports to work, which was the original motivation of #18983.

I confirmed provided reproductions are fixed with pr package (except there is a case like #19929 (comment), which is due to another fix #19841, so they are still expected to be addressed on user side).

On Vitest side, there might be more complicated scenarios with mocking, so I couldn't actually tell whether it's an cyclic imports issues. We'll revisit whether we should remove try/catch after investigating that further.

sheremet-va
sheremet-va previously approved these changes May 1, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented May 1, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@19959

commit: adbfb90

@hi-ogawa hi-ogawa marked this pull request as ready for review May 2, 2025 00:21
@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented May 2, 2025

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

hi-ogawa and others added 2 commits May 2, 2025 16:21
Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
@patak-cat patak-cat merged commit fd38d07 into vitejs:main May 2, 2025
16 checks passed
@hi-ogawa hi-ogawa deleted the fix-tolerate-no-init-as-undefined branch May 2, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vitest with Vite 6.3.x regressed and started failing v6.3.3 ReferenceError: Cannot access '__vite_ssr_export_default__' before initialization

3 participants