Fix #1733: [Bug] @memtensor/memos-lite-openclaw-plugin v0.2.3 fails to load: ReferenceError#2047
Merged
syzsunshine219 merged 2 commits intoJul 2, 2026
Conversation
…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
Collaborator
Author
🤖 Open Code ReviewTarget: PR #2047 ✅ OpenCodeReview: No supported files changed. Generated by cloud-assistant via Open Code Review. |
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (4/4 executed). memos_local_openclaw/unit: 4/4. Duration: 3s Branch: |
# Conflicts: # apps/memos-local-openclaw/tsconfig.json
Collaborator
Author
|
Automated Test Results: QUEUED This AutoDev PR was retargeted to
I will post the final pass/fail result when the run completes. |
Collaborator
Author
Automated Test Results: PASSEDCloud test-engine run
This PR has cloud test coverage for the changed OpenClaw scope. Manual review is still required before merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-pluginv0.2.3 ("ReferenceError: exports is not defined in ES module scope") cannot recur.Root cause:
apps/memos-local-openclaw/tsconfig.jsonhad"module": "CommonJS"+"moduleResolution": "node", butpackage.jsondeclares"type": "module". When the legacy v0.2.3 build accidentally shipped itsdist/output, Node 22 read the compiled CommonJS wrappers (exports.initPlugin = ...) as ESM and refused to load them. The successor plugin doesn't currently shipdist/(itsfileslist excludes it, and OpenClaw loadsindex.tsdirectly 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 siblingapps/memos-local-pluginand 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,moduleResolutionis ESM-safe, and no.cjsentry point sneaks back intomainoropenclaw.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 --noEmitclean;tscbuild now emits ESM (import/export) with zeroexports./module.exportsmarkers indist/*.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.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist