Skip to content

fix: apply cjs interop for truthy __esModule - #10363

Merged
sheremet-va merged 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix-apply-csj-interop-for-truthy-esmodule
May 18, 2026
Merged

sheremet-va merged 3 commits into
vitest-dev:mainfrom
hi-ogawa:fix-apply-csj-interop-for-truthy-esmodule

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented May 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

As written in #10359 (comment), Bun defines __esModule export for genuine esm in a way '__esModule' in mod === true but mod.__esModule === undefined. This behavior is Bun specific quirk, but Vitest applying interop based on __esModule property existence seems less conventional and can be naturally mitigated on Vitest side by detecting truthy __esModule. That's what PR changes.

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

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:.

@netlify

netlify Bot commented May 16, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3409b9b
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a08075c3330940008d0b16f
😎 Deploy Preview https://deploy-preview-10363--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa changed the title fix: apply csj interop for truthy __esModule fix: apply cjs interop for truthy __esModule May 16, 2026
@hi-ogawa
hi-ogawa marked this pull request as ready for review May 16, 2026 06:39
@sheremet-va

Copy link
Copy Markdown
Member

I don’t think we should change the behavior for bun. The interop is applied because Node cannot handle it specifically. deps.interopDefault is not required for bun at all, I think. It might be better to just disable it in that runtime

@hi-ogawa

hi-ogawa commented May 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

I don’t think we should change the behavior for bun. The interop is applied because Node cannot handle it specifically. deps.interopDefault is not required for bun at all, I think. It might be better to just disable it in that runtime

Testing '__esModule' in value instead of value.__esModule doesn't look specifically intended though. I wouldn't be actually invested on Bun specific behavior to verify interopDefault is necessary or not, so if you are not merging this, I'll close this.

@sheremet-va

sheremet-va commented May 17, 2026 •

Copy link
Copy Markdown
Member

I’m not stopping the merge, I just want to discuss this first

Testing '__esModule' in value instead of value.__esModule doesn't look specifically intended though

Why isn’t it intended? One use case I see is proxies throwing errors (I think this is why it’s “in” right now)

@hi-ogawa

Copy link
Copy Markdown
Collaborator Author

Checking m.__esModule truthiness is the tradition as far as I understand since what babel and tsc do is something like Object.defineProperty(exports, "__esModule", { value: true }) https://www.typescriptlang.org/docs/handbook/2/modules.html#commonjs

Like this code

return m?.__esModule ? m : { ...((typeof m === 'object' && !Array.isArray(m)) || typeof m === 'function' ? m : {}), default: m }
and also some snippet in Vite also has m.__esModule ? ... style.

@sheremet-va

Copy link
Copy Markdown
Member

Ok, I don't have a strong case against it, although I still believe for bun we should just change the default since it's not required in that environment.

@sheremet-va
sheremet-va merged commit 2b13547 into vitest-dev:main May 18, 2026
14 of 16 checks passed
@hi-ogawa
hi-ogawa deleted the fix-apply-csj-interop-for-truthy-esmodule branch May 18, 2026 07:42
eduvhc added a commit to iedora/platform that referenced this pull request May 29, 2026
vitest 4.1.7 testa `'__esModule' in mod` em vez de truthiness, e o Bun
deixa a propriedade presente mas undefined → `import { z } from 'zod'`
resolve para undefined dentro do node-symlinked-to-bun do oven/bun:1.3-debian.
Mac usa node real, por isso só o CI falha.

Corrigido upstream em vitest-dev/vitest#10363 (mergeado 2026-05-18),
ainda não disponível em stable. 5.0.0-beta.3 inclui o fix.

Falha original: 5 test files do products/menu (`z.object`/`z.enum` undefined)
em git.iedora.com/eduvhc/iedora/actions/runs/8/jobs/40.
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bun runner makes import { z } from zod undefined

2 participants