Skip to content

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

Merged
syzsunshine219 merged 2 commits into
MemTensor:dev-v2.0.22from
Memtensor-AI:bugfix/autodev-1733
Jul 2, 2026
Merged

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

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Fixed issue #1733: aligned the successor plugin's TypeScript build with its declared module type so the ESM/CJS mismatch that broke @memtensor/memos-lite-openclaw-plugin v0.2.3 ("ReferenceError: exports is not defined in ES module scope") cannot recur.

Root cause: apps/memos-local-openclaw/tsconfig.json had "module": "CommonJS" + "moduleResolution": "node", but package.json declares "type": "module". When the legacy v0.2.3 build accidentally shipped its dist/ output, Node 22 read the compiled CommonJS wrappers (exports.initPlugin = ...) as ESM and refused to load them. The successor plugin doesn't currently ship dist/ (its files list excludes it, and OpenClaw loads index.ts directly via tsx), so the crash is latent — but the misalignment sat exactly on the seed of the reported bug, and the source already uses ESM-only constructs (import.meta.url, createRequire(import.meta.url)).

Fix (2 files, +99/-2):

  • apps/memos-local-openclaw/tsconfig.json: module -> ES2022, moduleResolution -> bundler (matches sibling apps/memos-local-plugin and the "type": "module" declaration).
  • apps/memos-local-openclaw/tests/module-format.test.ts: new regression guard that pins the invariant — package.json "type": "module" implies tsconfig emits an ESM module format, moduleResolution is ESM-safe, and no .cjs entry point sneaks back into main or openclaw.extensions. Verified to fail with the exact v0.2.3 diagnostic when tsconfig is reverted to the old CommonJS setup, and to pass with the fix.

Verification: vitest run tests/module-format.test.ts -> 4/4 passed; tsc --noEmit clean; tsc build now emits ESM (import/export) with zero exports. / module.exports markers in dist/*.js; sanity-checked chunker / config / storage / plugin-openclaw-wiring / plugin-impl-access suites (32 tests) still pass. Branch pushed to origin/bugfix/autodev-1733; task archived to memos-autodev-specs.

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

…module"

Issue MemTensor#1733 reported that the legacy @memtensor/memos-lite-openclaw-plugin
v0.2.3 failed to load on Node 22 / OpenClaw 2026.5.7 with
"ReferenceError: exports is not defined in ES module scope". Root cause:
tsc emitted CommonJS (exports.initPlugin = ...) into dist/, while
package.json declared "type": "module", so Node refused to evaluate the
compiled entry as ESM.

The same latent misalignment lived in the successor plugin at
apps/memos-local-openclaw: tsconfig.json had "module": "CommonJS" +
"moduleResolution": "node" while package.json still declares
"type": "module". It doesn't manifest today because "files" excludes
dist/ and the plugin loads index.ts directly via tsx, but any accidental
inclusion of dist/ (as v0.2.3 did) would reproduce the same crash.
The source is already ESM-native — index.ts uses import.meta.url and
createRequire(import.meta.url).

Changes:
- tsconfig.json: module "CommonJS" -> "ES2022";
  moduleResolution "node" -> "bundler". Now consistent with sibling
  apps/memos-local-plugin and with package.json "type": "module".
- tests/module-format.test.ts: new regression guard asserting the
  invariant "package.json type=module implies tsconfig emits ESM +
  moduleResolution is ESM-safe + no .cjs entry point sneaks into
  main/openclaw.extensions". Verified to fail (with the exact v0.2.3
  diagnostic) when tsconfig is reverted to the old CommonJS setup.

Verification:
- vitest run tests/module-format.test.ts -> 4/4 passed
- tsc --noEmit -> clean
- tsc build -> dist/*.js emit ESM (import/export), no exports./module.exports
- Sanity: chunker/config/storage/plugin-openclaw-wiring/plugin-impl-access
  tests (32 total) still pass unchanged.

Refs: MemTensor#1733
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

🤖 Open Code Review

Target: PR #2047
Task: 619791af6876622c
Base: dev-20260624-v2.0.22
Head: bugfix/autodev-1733

OpenCodeReview: No supported files changed.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

✅ Automated Test Results: PASSED

All tests passed (4/4 executed). memos_local_openclaw/unit: 4/4. Duration: 3s

Branch: bugfix/autodev-1733

# Conflicts:
#	apps/memos-local-openclaw/tsconfig.json
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

Automated Test Results: QUEUED

This AutoDev PR was retargeted to dev-v2.0.22, its merge conflict was resolved, and cloud test-engine rerun has been queued.

  • Run: tr-1ceb189e-1fe on cloud test-engine 10010
  • Branch tested: refs/pull/2047/head

I will post the final pass/fail result when the run completes.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

Automated Test Results: PASSED

Cloud test-engine run tr-1ceb189e-1fe completed successfully.

  • Base: dev-v2.0.22
  • Scopes tested: memos_local_openclaw
  • Result: 4/4 tests passed
  • Duration: 3s

This PR has cloud test coverage for the changed OpenClaw scope. Manual review is still required before merge.

@syzsunshine219 syzsunshine219 merged commit 2270510 into MemTensor:dev-v2.0.22 Jul 2, 2026
16 checks passed
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 | 功能异常

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants