Fix #1733: [Bug] @memtensor/memos-lite-openclaw-plugin v0.2.3 fails to load: ReferenceError#1996
Conversation
…dule The package declared "type": "module" but the tsconfig used "module": "CommonJS", so any `npm run build` produced dist/*.js files containing `Object.defineProperty(exports, ...)` and `exports.X = ...`. Under Node 22's ESM loader (enforced by type:module), those files crashed with `ReferenceError: exports is not defined in ES module scope`, breaking the @memtensor/memos-lite-openclaw-plugin v0.2.3 release on OpenClaw 2026.5.7. Switch the tsconfig to `module: ES2022` + `moduleResolution: Bundler` (the same pair already used by apps/memos-local-plugin/) and add a regression vitest case that guards the invariant going forward. Source under src/ is unchanged; the entry index.ts already uses ESM idioms (import.meta.url), so downgrading to CJS was never a valid alternative. Fixes #1733.
❌ Automated Test Results: FAILED
Failed tests:
Error detailsBranch: |
Issue #1733: @memtensor/memos-lite-openclaw-plugin v0.2.3 failed to load with "ReferenceError: exports is not defined in ES module scope" because the published tarball declared `"type": "module"` in package.json while shipping `dist/*.js` files compiled as CommonJS (`exports.xxx = ...` + `require(...)`). The current v1.0.9-beta.1 already addresses this structurally by publishing source-only (`files` lists `index.ts` + `src/` + explicit `.cjs` scripts, no `dist/`), but two latent regressions remained: 1. tsconfig.json still emitted CommonJS (`"module": "CommonJS"`), so a developer running `npm run build` locally would regenerate exactly the v0.2.3 conflict in the build output. 2. There was no regression test pinning the invariant that ESM-flavoured `package.json` must not ship bare `.js` files or a `dist/` directory. Changes: - tsconfig.json: switch `module` to `ES2022` and `moduleResolution` to `Bundler` so any local build emits ESM-flavoured `.js` matching the package's `type: "module"` declaration. - tests/esm-module-format.test.ts: 6 regression assertions covering package.json type/files/main, openclaw.extensions entry kinds, and tsconfig module kind. Confirmed the test fails when the v0.2.3 conditions are re-introduced and passes once they are not.
|
Cloud verification update (test-engine v2): PASSED. Run |
|
Automated Test Results: PASSED\n\nCloud test-engine rerun after resolving the dev-v2.0.22 merge conflict.\n\nRun: tr-a0daeac6-71b\nScope: memos_local_openclaw\nResult: 8/8 tests passed\nCommand group: memos_local_openclaw/unit\nDuration: 3s\n\nLocal pre-push verification also passed: npm run build, plus focused vitest for esm-module-format. The regression test was aligned with dev-v2.0.22's dist-based ESM publish model: dist/index.js is allowed only because tsconfig now emits ESM, not CommonJS.\n\nStatus: merge conflict resolved; automated scope test passed. Manual code review is still required before merge. |
Description
Fixed #1733 (
@memtensor/memos-lite-openclaw-plugin v0.2.3failing to load under Node 22 + OpenClaw 2026.5.7 withReferenceError: exports is not defined in ES module scope).Root cause:
apps/memos-local-openclaw/package.jsondeclares"type": "module"butapps/memos-local-openclaw/tsconfig.jsonwas set to"module": "CommonJS", so anytscrun emitsdist/*.jsfiles containingObject.defineProperty(exports, ...)/exports.X = ...markers. Node's ESM loader (enforced bytype:module) refuses to evaluate that shape and throws. The plugin entryindex.ts:167usesimport.meta.url, so downgrading the package to CommonJS (the issue reporter's first suggestion) is not viable — the only correct fix is makingtscemit ESM.Fix: switch
apps/memos-local-openclaw/tsconfig.jsonto"module": "ES2022"+"moduleResolution": "Bundler"+"allowSyntheticDefaultImports": true— identical pairing to the siblingapps/memos-local-plugin/tsconfig.jsonwhich has no such bug. Addedapps/memos-local-openclaw/tests/esm-module-format.test.ts(5 vitest assertions) to lock in the invariants: package keepstype:module, tsconfig never regresses to CJS emit, dist (if present) is never CJS-shaped, andfilesstays source-only.Verification (verification-report.md): bug reproduced byte-for-byte in /tmp/memos-repro/ with the old tsconfig; regression test 2/5 failing on the unfixed branch and 5/5 passing after the fix;
tsc --noEmit -p tsconfig.jsonclean on the full src/ tree; realtscbuild produces 0Object.defineProperty(exports,markers and 330 ESMexportstatements; built dist loads successfully under Node 22 +type:module. No source undersrc/is touched — pure build-config + test additions.Related Issue (Required): Fixes #1733
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist