Skip to content

Commit 019f3bb

Browse files
committed
fix(esm): handle missing hot update manifests in Node.js
1 parent 94a4bcd commit 019f3bb

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Handle missing ESM hot update manifests in Node.js without failing HMR checks.

‎lib/esm/ModuleChunkLoadingRuntimeModule.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
568568
}()).then(${runtimeTemplate.basicFunction("obj", [
569569
"return obj.default;"
570570
])}, ${runtimeTemplate.basicFunction("error", [
571-
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(error.code)) return;",
571+
"if(['MODULE_NOT_FOUND', 'ERR_MODULE_NOT_FOUND', 'ENOENT'].includes(error.code)) return;",
572572
"throw error;"
573573
])});`
574574
])};`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import update from "../../update.esm.js";
2+
3+
if (import.meta.webpackHot) {
4+
import.meta.webpackHot.accept();
5+
}
6+
7+
it("should apply an available update", done => {
8+
NEXT(update(done, true, () => done()));
9+
});
10+
---
11+
it("should ignore ERR_MODULE_NOT_FOUND when no update is available", done => {
12+
import.meta.webpackHot.check()
13+
.then(updatedModules => {
14+
expect(updatedModules).toBe(null);
15+
expect(import.meta.webpackHot.status()).toBe("idle");
16+
return import.meta.webpackHot.check();
17+
})
18+
.then(updatedModules => {
19+
expect(updatedModules).toBe(null);
20+
expect(import.meta.webpackHot.status()).toBe("idle");
21+
done();
22+
})
23+
.catch(done);
24+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
module.exports = {
4+
output: {
5+
module: true,
6+
// The test loader reports ENOENT for missing files; native import() uses
7+
// ERR_MODULE_NOT_FOUND instead.
8+
importFunctionName:
9+
"((url) => import(url).catch(error => { if (error.code === 'ENOENT') error.code = 'ERR_MODULE_NOT_FOUND'; throw error; }))",
10+
library: {
11+
type: "module"
12+
}
13+
}
14+
};

0 commit comments

Comments
 (0)