#17237: fix(update): guard post-install imports after npm global update
channel: whatsapp-web
cli
stale
size: M
Cluster:
Update Handling Fixes
## Summary
- Fixes a regression where `openclaw update` on npm-global installs could fail after update with `ERR_MODULE_NOT_FOUND`.
- Root cause: updater code could lazily import hashed dist chunks (`daemon-cli-*`, `doctor-*`) **after** npm replaced `dist/` files.
- Change: keep those imports eager in `update-command.ts` and add a focused regression test to lock behavior.
- Scope boundary: no update algorithm changes, no package-manager behavior changes, no service lifecycle changes.
## Linked Issue
- Closes #17225
## User-visible Impact
- No new flags/defaults.
- Prevents false-looking failed updates caused by stale chunk imports post-upgrade.
## Verification
### Repro (before)
1. Install affected version: `npm i -g openclaw@2026.2.2-3`
2. Run: `openclaw update --yes`
3. Observe possible failure like:
- `ERR_MODULE_NOT_FOUND` for `daemon-cli-<oldhash>.js` imported by `update-cli-<oldhash>.js`
### Validation (after)
- Ran focused tests:
- `pnpm -s vitest run src/cli/update-cli.test.ts src/cli/update-cli/update-command.postinstall-import.test.ts`
- Confirmed updater output no longer relies on lazy post-update imports for daemon/doctor chunks.
## Security / Compatibility
- Security impact: none
- Backward compatible: yes
- Migration/config changes: none
## Risks & Mitigation
- Risk: regression test could become too tied to implementation details.
- Mitigation: test asserts behavioral ordering under simulated dist replacement, not hash snapshots.
## Rollback
- Revert this PR commits affecting:
- `src/cli/update-cli/update-command.ts`
- `src/cli/update-cli/update-command.postinstall-import.test.ts`
---
AI-assisted: yes (Codex), human-reviewed and validated.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Prevents `ERR_MODULE_NOT_FOUND` errors during `openclaw update` on npm-global installs by ensuring `daemon-cli` and `doctor` modules are eagerly imported before npm replaces hashed dist chunks. The fix moves two imports to the top of `update-command.ts` with clear comments explaining the rationale. Includes a focused regression test that simulates the update process to lock in the behavior. The `media.test.ts` change uses `mkdtemp` for safer temporary directory handling in tests.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are minimal, well-targeted, and directly address the reported issue. The fix converts two lazy imports to eager imports with clear explanatory comments. The regression test is comprehensive and validates the exact scenario that was failing. The media.test.ts change is an unrelated test infrastructure improvement that reduces CI flakiness.
- No files require special attention
<sub>Last reviewed commit: 151b61d</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22406: Fix update detection for Companion App npm-prefix installs
by graysurf · 2026-02-21
83.2%
#20585: fix: pre-flight ownership check before global update
by mwfj · 2026-02-19
82.9%
#8600: fix(update): add --ignore-scripts to prevent supply chain attacks
by yubrew · 2026-02-04
82.5%
#18961: fix: detect pnpm package manager in openclaw update
by norci · 2026-02-17
81.8%
#17815: fix: use $HOME as cwd for global update to prevent path-dedot panic
by frankekn · 2026-02-16
81.4%
#19801: fix: pre-check write permissions before global install to prevent E...
by menhguin · 2026-02-18
80.7%
#23730: fix(update): correctly compare versions with -N build suffix
by mrx-arafat · 2026-02-22
80.4%
#12804: fix(daemon): use wrapper script for pnpm global installs in service...
by odinho · 2026-02-09
79.5%
#16016: fix: update systemd unit version on gateway restart
by jbold · 2026-02-14
79.5%
#17230: fix: preload daemon-cli module before npm update
by MisterGuy420 · 2026-02-15
79.1%