mirror of https://github.com/webpack/webpack.git
fix: unify the error handling for hmrDownloadManifest (#19835)
This commit is contained in:
parent
a0f19f7c50
commit
914db1f7ca
|
@ -392,8 +392,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
[
|
||||
`return ${importFunctionName}(/* webpackIgnore: true */ url).then(onResolve).catch(onReject)`
|
||||
]
|
||||
)}
|
||||
loadScript(url, onResolve, onReject);`
|
||||
)}`,
|
||||
"loadScript(url, onResolve, onReject);"
|
||||
]
|
||||
)});`
|
||||
]),
|
||||
|
@ -411,7 +411,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}()).then(${runtimeTemplate.basicFunction("obj", [
|
||||
"return obj.default;"
|
||||
])}, ${runtimeTemplate.basicFunction("", "")});`
|
||||
])}, ${runtimeTemplate.basicFunction("error", [
|
||||
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(error.code)) return;",
|
||||
"throw error;"
|
||||
])});`
|
||||
])};`
|
||||
])
|
||||
: "// no HMR manifest"
|
||||
|
|
|
@ -264,7 +264,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
Template.indent([
|
||||
"if(err) {",
|
||||
Template.indent([
|
||||
'if(err.code === "ENOENT") return resolve();',
|
||||
'if(["MODULE_NOT_FOUND", "ENOENT"].includes(err.code)) return resolve();',
|
||||
"return reject(err);"
|
||||
]),
|
||||
"}",
|
||||
|
|
|
@ -223,7 +223,10 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|||
RuntimeGlobals.getUpdateManifestFilename
|
||||
}());`
|
||||
]),
|
||||
"})['catch'](function(err) { if(err.code !== 'MODULE_NOT_FOUND') throw err; });"
|
||||
`}).catch(${runtimeTemplate.basicFunction("err", [
|
||||
"if(['MODULE_NOT_FOUND', 'ENOENT'].includes(err.code)) return;",
|
||||
"throw err;"
|
||||
])});`
|
||||
]),
|
||||
"}"
|
||||
])
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
if (module.hot) {
|
||||
module.hot.accept()
|
||||
}
|
||||
it('Should work', (done) => {
|
||||
expect(1).toBe(1)
|
||||
NEXT(
|
||||
require("../../update")(done, true, () => {
|
||||
done();
|
||||
})
|
||||
);
|
||||
})
|
||||
---
|
||||
// https://github.com/webpack/webpack/pull/19832#event-19319802751
|
||||
// This is because within the checkForUpdate(hot/signal.js), we will proactively check for updates again. If there are no updates at this time, it is acceptable.
|
||||
it('Should be no error when the HMR update detects that the hot-update.json file does not exist', (done) => {
|
||||
expect(1).toBe(1)
|
||||
__webpack_require__.hmrM().then(() => {
|
||||
done()
|
||||
}).catch((err) => {
|
||||
done(err)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,25 @@
|
|||
import update from "../../update.esm.js";
|
||||
|
||||
|
||||
if (import.meta.webpackHot) {
|
||||
import.meta.webpackHot.accept()
|
||||
}
|
||||
it('Should work', (done) => {
|
||||
expect(1).toBe(1)
|
||||
NEXT(
|
||||
update(done, true, () => {
|
||||
done();
|
||||
})
|
||||
);
|
||||
})
|
||||
---
|
||||
// https://github.com/webpack/webpack/pull/19832#event-19319802751
|
||||
// This is because within the checkForUpdate(hot/signal.js), we will proactively check for updates again. If there are no updates at this time, it is acceptable.
|
||||
it('Should be no error when the HMR update detects that the hot-update.json file does not exist', (done) => {
|
||||
expect(1).toBe(1)
|
||||
__webpack_require__.hmrM().then(() => {
|
||||
done()
|
||||
}).catch((err) => {
|
||||
done(err)
|
||||
})
|
||||
})
|
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
experiments: {
|
||||
outputModule: true
|
||||
},
|
||||
output: {
|
||||
module: true,
|
||||
library: {
|
||||
type: "module"
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue