Skip to content

fix(rvf-wasm): publish as ESM-only to resolve #415#431

Open
ruvnet wants to merge 1 commit intomainfrom
fix/issue-415-rvf-wasm-esm-cjs
Open

fix(rvf-wasm): publish as ESM-only to resolve #415#431
ruvnet wants to merge 1 commit intomainfrom
fix/issue-415-rvf-wasm-esm-cjs

Conversation

@ruvnet
Copy link
Copy Markdown
Owner

@ruvnet ruvnet commented May 7, 2026

Summary

Fix

  • Add "type": "module" and switch mainpkg/rvf_wasm.mjs.
  • Drop the require/default exports that pointed at the broken CJS-classified .js. Node 22.12+ supports require(ESM) natively, so a single ESM entry covers both consumers.
  • Add tests/smoke.mjs regression guard (also wired into prepublishOnly) that imports the package, calls init(), asserts real WASM memory, and confirms idempotency.
  • Bump 0.1.5 → 0.1.7 (skip the broken 0.1.6).

Proof

End-to-end against a packed tarball installed into /tmp on Node 22.22.2:

$ npm pack
ruvector-rvf-wasm-0.1.7.tgz

$ node --input-type=module -e "import('@ruvector/rvf-wasm').then(m => m.default()).then(e => console.log('memory bytes:', e.memory.buffer.byteLength))"
memory bytes: 1179648

$ node -e "require('@ruvector/rvf-wasm')"
# succeeds (Node 22.12+ require(ESM))

$ npm test
  ok: mjs default export is a function
  ok: init() returned exports object
  ok: exports.memory is WebAssembly.Memory
  ok: init() is idempotent

rvf-wasm smoke OK

Test plan

  • npm pack succeeds; tarball contents unchanged (6 files, 21 KB).
  • ESM await import('@ruvector/rvf-wasm') resolves and default() returns real WASM exports.
  • CJS require('@ruvector/rvf-wasm') works on Node 22.12+ (no SyntaxError).
  • npm test passes (tests/smoke.mjs).
  • prepublishOnly runs the smoke test before any future publish.
  • Manual: re-run ruflo memory init against a stack pinning @ruvector/rvf-wasm@0.1.7 once published.

Notes

  • Local consumers (@ruvector/rvf ^0.1.5, @ruvector/rvlite >=0.1.0) are unchanged — both already use await import('@ruvector/rvf-wasm'), which now works.
  • Workaround in the issue (sed-patching installed package.json) is no longer needed once 0.1.7 is published.
  • This PR does NOT publish — version bump is in-tree only; release pipeline owns the actual npm publish.

🤖 Generated with claude-flow

The published 0.1.6 tarball was unloadable: pkg/rvf_wasm.js used
`import.meta.url` and `export default` while package.json had no
`"type": "module"`, so Node parsed it as CJS and threw
`SyntaxError: Cannot use 'import.meta' outside a module` before any
runtime guard could execute. The .mjs entry just re-imported the same
broken .js, so the ESM path crashed identically.

Fix:
- Add `"type": "module"` and switch `main` to `pkg/rvf_wasm.mjs`.
- Drop the `require`/`default` exports that pointed at the broken
  CJS-classified .js. Node 22.12+ supports `require(ESM)` natively, so
  the single ESM entry covers both consumers.
- Add `tests/smoke.mjs` as a regression guard (also wired into
  `prepublishOnly`) that imports the package, calls `init()`, asserts
  real WASM memory, and confirms idempotency.
- Bump 0.1.5 → 0.1.7 (skip the broken 0.1.6).

Verified end-to-end against a packed tarball installed into /tmp:
ESM import works (1.1 MB memory allocated), CJS require also works on
Node 22.22.2.

Closes #415

Co-Authored-By: claude-flow <ruv@ruv.net>
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.

@ruvector/rvf-wasm@0.1.6 is unloadable: pkg/rvf_wasm.js mixes ESM syntax (import.meta, export default) into CJS-classified file

1 participant