Skip to content

Fix #1733: [Bug] @memtensor/memos-lite-openclaw-plugin v0.2.3 fails to load: ReferenceError#1996

Merged
syzsunshine219 merged 3 commits into
dev-v2.0.22from
bugfix/autodev-1733
Jul 2, 2026
Merged

Fix #1733: [Bug] @memtensor/memos-lite-openclaw-plugin v0.2.3 fails to load: ReferenceError#1996
syzsunshine219 merged 3 commits into
dev-v2.0.22from
bugfix/autodev-1733

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Fixed #1733 (@memtensor/memos-lite-openclaw-plugin v0.2.3 failing to load under Node 22 + OpenClaw 2026.5.7 with ReferenceError: exports is not defined in ES module scope).

Root cause: apps/memos-local-openclaw/package.json declares "type": "module" but apps/memos-local-openclaw/tsconfig.json was set to "module": "CommonJS", so any tsc run emits dist/*.js files containing Object.defineProperty(exports, ...) / exports.X = ... markers. Node's ESM loader (enforced by type:module) refuses to evaluate that shape and throws. The plugin entry index.ts:167 uses import.meta.url, so downgrading the package to CommonJS (the issue reporter's first suggestion) is not viable — the only correct fix is making tsc emit ESM.

Fix: switch apps/memos-local-openclaw/tsconfig.json to "module": "ES2022" + "moduleResolution": "Bundler" + "allowSyntheticDefaultImports": true — identical pairing to the sibling apps/memos-local-plugin/tsconfig.json which has no such bug. Added apps/memos-local-openclaw/tests/esm-module-format.test.ts (5 vitest assertions) to lock in the invariants: package keeps type:module, tsconfig never regresses to CJS emit, dist (if present) is never CJS-shaped, and files stays 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.json clean on the full src/ tree; real tsc build produces 0 Object.defineProperty(exports, markers and 330 ESM export statements; built dist loads successfully under Node 22 + type:module. No source under src/ is touched — pure build-config + test additions.

Related Issue (Required): Fixes #1733

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

…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.
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

❌ Automated Test Results: FAILED

Auto-fix retry 1/2 triggered.

Failed tests:

  • test_out_of_range_rejected_or_clamped_to_valid[negative_1]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_60s]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_1]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[hundred_x_max]
  • test_invalid_type_does_not_crash_or_corrupt[string_number]
  • test_invalid_type_does_not_crash_or_corrupt[string_text]
  • test_invalid_type_does_not_crash_or_corrupt[none_value]
  • test_invalid_type_does_not_crash_or_corrupt[dict_value]
Error details
The memos_local_plugin SUT does not validate or clamp the `vector_scan_max_age` field on PATCH: negative values, out-of-range values, and non-numeric types (strings, None, dicts) are accepted and persisted unchanged, then returned as-is on GET.

Branch: bugfix/autodev-1733

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.
@syzsunshine219 syzsunshine219 changed the base branch from dev-20260624-v2.0.22 to dev-v2.0.22 July 1, 2026 07:14
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

Cloud verification update (test-engine v2): PASSED.

Run tr-5309e313-d92 executed focused memos_local_openclaw/unit: 8/8 passed. GitHub checks are green; remaining gates are update branch if required, human review, and branch protection.

@CarltonXiang CarltonXiang added the plugin Plugin/adapter/bridge layer (apps/ directory) | 插件/适配层 label Jul 2, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

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.

@syzsunshine219 syzsunshine219 merged commit 44bec71 into dev-v2.0.22 Jul 2, 2026
16 checks passed
@syzsunshine219 syzsunshine219 deleted the bugfix/autodev-1733 branch July 2, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated bug Something isn't working | 功能异常 plugin Plugin/adapter/bridge layer (apps/ directory) | 插件/适配层

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants