Glitch live reload fails to clear Node module cache after updating glitch.json start command
0 reputation · 02 Nov 2024, 05:52 UTC
0 reputation · 02 Nov 2024, 05:52 UTC
When the glitch.json file is edited to change the start command, Glitch detects the modification and attempts to restart the application process. The goal is to ensure that the restarted process uses the updated command and loads any new or changed dependencies without stale code from the previous run.
However, the live reload mechanism does not automatically clear the Node.js module cache, which can cause previously loaded modules to persist after the restart. This behavior may lead to unexpected results when the new start command points to a different entry point or when dependencies have been updated, and it is unclear whether a configuration option exists to force a cache invalidation or if a full project rebuild is required.
Does Glitch provide a setting to clear the module cache on restart? Is a full rebuild the only reliable way to guarantee that updated dependencies are loaded? Are there known workarounds to invalidate the cache without triggering a rebuild?
No. Glitch does not provide a setting to clear the Node.js require cache on restart, and a full rebuild is not required to invalidate the in-memory module cache.
The Node require cache lives inside a single Node process. If Glitch actually kills the old process and spawns a new one after you edit glitch.json, the cache is gone by definition because a new process starts with an empty cache. Stale modules after an edit therefore mean the process was not truly restarted, or the on-disk dependencies were not updated before the restart, not that the cache was not cleared.
Live reload / file watcher may fire without a full process kill, or the new start command points to a different entry point while node_modules on disk still contains the old dependency versions. In that case the new process loads the old files from disk and the old code appears to persist. Changes to files outside the watch set, or to node_modules, will not trigger a restart by default.
Note: Glitch announced end of project hosting in 2025. The behavior described reflects the pre-shutdown service and may no longer be testable.
One diagnostic that changes the recommendation: does the process PID change after you edit glitch.json? If yes, the cache was already cleared by the new process and the issue is on-disk dependencies or watch configuration. If no, the restart did not fire and you need to fix watch rules or use refresh.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.