Skip to content

fix(vite-node): named export should overwrite export all #7846

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

Merged
merged 2 commits into from
Apr 17, 2025

Conversation

hi-ogawa
Copy link
Contributor

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

Description

Porting vitejs/vite#19534 to fix vitejs/vite#19525 on Vite-node. I forgot we need to have the same thing here when the fix is in runtime but not in transform.

The bug is now always happen when ssr transform hoists each named export vitejs/vite#18983.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@hi-ogawa hi-ogawa marked this pull request as ready for review April 17, 2025 04:43
@sheremet-va sheremet-va merged commit 5ba0d91 into vitest-dev:main Apr 17, 2025
12 of 13 checks passed
@hi-ogawa hi-ogawa deleted the fix-port-vite-19534 branch April 17, 2025 09:39
schogges pushed a commit to kumahq/kuma-gui that referenced this pull request Apr 23, 2025
v3.1.2
   🐞 Bug Fixes
Add global chai variable in vitest/globals (fix: #7474)  -  by @​Jay-Karia in vitest-dev/vitest#7771 and vitest-dev/vitest#7474 (d9297)
Prevent modifying test.exclude when same object passed in coverage.exclude  -  by @​AriPerkkio in vitest-dev/vitest#7774 (c3751)
Fix already hoisted mock  -  by @​hi-ogawa in vitest-dev/vitest#7815 (773b1)
Fix test.scoped inheritance  -  by @​hi-ogawa in vitest-dev/vitest#7814 (db6c3)
Remove pointer-events-none after resizing the left panel  -  by @​alexprudhomme in vitest-dev/vitest#7811 (a7e77)
Default to run mode when stdin is not a TTY  -  by @​kentonv, @​hi-ogawa and @​sheremet-va in vitest-dev/vitest#7673 (6358f)
Use happy-dom/jsdom types for envionmentOptions  -  by @​hi-ogawa in vitest-dev/vitest#7795 (67430)
browser:
Fix transform error before browser server initialization  -  by @​hi-ogawa in vitest-dev/vitest#7783 (5f762)
Fix mocking from outside of root  -  by @​hi-ogawa in vitest-dev/vitest#7789 (03f55)
Scale iframe for non ui case  -  by @​hi-ogawa in vitest-dev/vitest#6512 (c3374)
coverage:
await profiler calls  -  by @​AriPerkkio in vitest-dev/vitest#7763 (795a6)
Expose profiling timers  -  by @​AriPerkkio in vitest-dev/vitest#7820 (5652b)
deps:
Update all non-major dependencies  -  in vitest-dev/vitest#7765 (7c3df)
Update all non-major dependencies  -  in vitest-dev/vitest#7831 (15701)
runner:
Correctly call test hooks and teardown functions  -  by @​sheremet-va in vitest-dev/vitest#7775 (3c00c)
Show stacktrace on test timeout error  -  by @​hi-ogawa in vitest-dev/vitest#7799 (df33b)
ui:
Load panel sizes from storage on initial load  -  by @​userquin in vitest-dev/vitest#7265 (6555d)
vite-node:
Named export should overwrite export all  -  by @​hi-ogawa in vitest-dev/vitest#7846 (5ba0d)
Add ERR_MODULE_NOT_FOUND code error if module cannot be loaded  -  by @​sheremet-va in vitest-dev/vitest#7776 (f9eac)
   🏎 Performance
browser: Improve browser parallelisation  -  by @​sheremet-va in vitest-dev/vitest#7665 (816a5)
@ghiscoding
Copy link
Contributor

ghiscoding commented Apr 28, 2025

@hi-ogawa what if this PR and the indirect changes still doesn't fix the issue brought by the hoisting Vite change? Because for me in Lerna-Lite project, I still see it failing when I enable pnpm lock file maintenance and it uses all latest versions of Vite/Vitest. For now I can stay on previous Vite 6.2.x to avoid the failures (I only use Vitest in Lerna-Lite, there's no use of Vite since it's not a web app but rather a Node app)

My failure are in this GitHub Actions workflow
https://github.com/lerna-lite/lerna-lite/actions/runs/14698826781/job/41244615531

and the PR (that I now closed to avoid failures in the project)
lerna-lite/lerna-lite#1024

I get these failures only when using Vite 6.3.x, while previous 6.2.x is all good. I haven't had a chance to really dig into the problem, I just decided to stay on previous Vite for now. Should I open a new Vitest issue?

⎯⎯⎯⎯⎯⎯ Failed Suites 6 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  packages/publish/src/__tests__/publish-from-git.spec.ts [ packages/publish/src/__tests__/publish-from-git.spec.ts ]
Error: [vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock
 ❯ packages/publish/src/__tests__/publish-from-git.spec.ts:35:1
     33| import { npmPublish } from '../lib/npm-publish.js';
     34| import { npmPublish as npmPublishMock } from '../lib/__mocks__/npm-pub…
     35| import { logOutput, promptConfirmation, PublishCommandOption, throwIfU…
       | ^
     36| 
     37| // helpers

Caused by: Error: [vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock
 ❯ packages/core/src/filter-packages/lib/filter-packages.ts:2:1

Caused by: ReferenceError: Cannot access 'Command' before initialization
 ❯ Module.get [as Command] packages/core/src/command.ts:1:103
 ❯ packages/publish/src/__tests__/publish-from-git.spec.ts:14:70
 ❯ packages/core/src/filter-packages/lib/filter-packages.ts:2:1

@hi-ogawa
Copy link
Contributor Author

@ghiscoding Please open a new issue. 🙏

@EvHaus
Copy link
Contributor

EvHaus commented Apr 28, 2025

I'm having the same issue as @ghiscoding. Some of my tests are unexpectedly failing with these errors:

ReferenceError: Cannot access '***' before initialization

Only after upgrading from Vite 6.2.6 to 6.3.3.

@ghiscoding
Copy link
Contributor

ghiscoding commented Apr 29, 2025

issue #7902 created, @EvHaus you can add any missing info in that issue. Thanks

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

Successfully merging this pull request may close these issues.

Vite SSR doesn't overwrite * re-export by named export
4 participants