Skip to content

[codex] fix Vitest Node WASM package export#1006

Merged
zxch3n merged 1 commit into
mainfrom
fix/vitest-node-wasm-export
Jun 8, 2026
Merged

[codex] fix Vitest Node WASM package export#1006
zxch3n merged 1 commit into
mainfrom
fix/vitest-node-wasm-export

Conversation

@zxch3n

@zxch3n zxch3n commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Fix loro-crdt package resolution for Node/Vitest bare imports by adding a node condition before the root import condition. This makes Node test runners resolve to the existing nodejs WASM entry instead of the bundler WASM entry.

The bundler smoke tests now exercise a stronger Loro scenario across generated apps: new Loro(), getMap(), ensureMergeableText(), text insertion, and toJSON() verification. A new vitest-node smoke case covers the issue #1005 path by installing loro-crdt into a temporary Vitest project and importing it by package name from node_modules.

Root Cause

loro-crdt@1.13.0 added conditional exports where ESM import resolved to ./bundler/index.js. Vitest externalizes dependencies in node_modules, so Node loaded the bundler WASM entry directly and hit undefined.memory during WASM startup. The Node-specific package condition should resolve to the Node entry before the generic import condition.

Validation

  • node --check examples/bundler-smoke-tests/scripts/run.mjs
  • node --check examples/bundler-smoke-tests/scripts/browser-runtime.mjs
  • node --check examples/bundler-smoke-tests/scripts/dev-runtime.mjs
  • Reproduced failure with LORO_SMOKE_PACKAGE=loro-crdt@1.13.0 pnpm --dir examples/bundler-smoke-tests run test vitest-node
  • Simulated the package export fix in the temporary Vitest install and confirmed loro-crdt resolves to nodejs/index.js and the Vitest test passes
  • pnpm exec vite build in the generated vite7 smoke project still emits the browser WASM asset
  • pnpm --dir examples/bundler-smoke-tests exec node ./scripts/browser-runtime.mjs vite7 passes with {"map":{"text":"mergeable-smoke"}}

@lodystage lodystage Bot marked this pull request as ready for review June 8, 2026 14:39
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

WASM Size Report

  • Original size: 3029.88 KB
  • Gzipped size: 999.17 KB
  • Brotli size: 701.74 KB

@zxch3n zxch3n merged commit 3978aa6 into main Jun 8, 2026
2 checks passed
zxch3n added a commit that referenced this pull request Jun 8, 2026
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.

1 participant