Skip to content

Commit

Permalink
fix(serve): explicitly bust require cache for cjs compatibility (#7487
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pcattori authored Sep 19, 2023
1 parent fccadba commit 8d68212
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/forty-needles-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@remix-run/serve": patch
---

Fix HMR for CJS projects using `remix-serve` and manual mode (`remix dev --manual`)

By explicitly busting the `require` cache, `remix-serve` now correctly reimports new server changes in CJS.
ESM projects were already working correctly and are not affected by this.
6 changes: 6 additions & 0 deletions packages/remix-serve/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ async function run() {
let versionPath = path.resolve(buildPath, "..", "version.txt");

async function reimportServer() {
Object.keys(require.cache).forEach((key) => {
if (key.startsWith(buildPath)) {
delete require.cache[key];
}
});

let stat = fs.statSync(buildPath);

// use a timestamp query parameter to bust the import cache
Expand Down

0 comments on commit 8d68212

Please sign in to comment.