Unverified Commit 7e11a155 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: improve missing factory message (#84881)

Don't mention HMR for prod builds
parent 1112dce6
...@@ -55,7 +55,7 @@ function instantiateModule( ...@@ -55,7 +55,7 @@ function instantiateModule(
// This can happen if modules incorrectly handle HMR disposes/updates, // This can happen if modules incorrectly handle HMR disposes/updates,
// e.g. when they keep a `setTimeout` around which still executes old code // e.g. when they keep a `setTimeout` around which still executes old code
// and contains e.g. a `require("something")` call. // and contains e.g. a `require("something")` call.
factoryNotAvailable(id, sourceType, sourceData) throw new Error(factoryNotAvailableMessage(id, sourceType, sourceData))
} }
const module: Module = createModuleObject(id) const module: Module = createModuleObject(id)
......
...@@ -194,7 +194,10 @@ function instantiateModule( ...@@ -194,7 +194,10 @@ function instantiateModule(
// This can happen if modules incorrectly handle HMR disposes/updates, // This can happen if modules incorrectly handle HMR disposes/updates,
// e.g. when they keep a `setTimeout` around which still executes old code // e.g. when they keep a `setTimeout` around which still executes old code
// and contains e.g. a `require("something")` call. // and contains e.g. a `require("something")` call.
factoryNotAvailable(id, sourceType, sourceData) throw new Error(
factoryNotAvailableMessage(id, sourceType, sourceData) +
' It might have been deleted in an HMR update.'
)
} }
const hotData = moduleHotData.get(id)! const hotData = moduleHotData.get(id)!
......
...@@ -106,11 +106,11 @@ const availableModules: Map<ModuleId, Promise<any> | true> = new Map() ...@@ -106,11 +106,11 @@ const availableModules: Map<ModuleId, Promise<any> | true> = new Map()
const availableModuleChunks: Map<ChunkPath, Promise<any> | true> = new Map() const availableModuleChunks: Map<ChunkPath, Promise<any> | true> = new Map()
function factoryNotAvailable( function factoryNotAvailableMessage(
moduleId: ModuleId, moduleId: ModuleId,
sourceType: SourceType, sourceType: SourceType,
sourceData: SourceData sourceData: SourceData
): never { ): string {
let instantiationReason let instantiationReason
switch (sourceType) { switch (sourceType) {
case SourceType.Runtime: case SourceType.Runtime:
...@@ -128,9 +128,7 @@ function factoryNotAvailable( ...@@ -128,9 +128,7 @@ function factoryNotAvailable(
(sourceType) => `Unknown source type: ${sourceType}` (sourceType) => `Unknown source type: ${sourceType}`
) )
} }
throw new Error( return `Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available.`
`Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`
)
} }
function loadChunk( function loadChunk(
......
;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="9cf0cfff-fe6b-e2a6-ed5a-275f25467c66")}catch(e){}}(); ;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="8faf1c28-5e36-9739-d4ef-60847ff8a1f3")}catch(e){}}();
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([ (globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push([
"output/ba425_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js", "output/ba425_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js",
{"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0b8736b3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]} {"otherChunks":["output/aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0b8736b3.js"],"runtimeModuleIds":["[project]/turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/input/index.js [test] (ecmascript)"]}
...@@ -523,7 +523,7 @@ const moduleFactories = new Map(); ...@@ -523,7 +523,7 @@ const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
const availableModuleChunks = new Map(); const availableModuleChunks = new Map();
function factoryNotAvailable(moduleId, sourceType, sourceData) { function factoryNotAvailableMessage(moduleId, sourceType, sourceData) {
let instantiationReason; let instantiationReason;
switch(sourceType){ switch(sourceType){
case 0: case 0:
...@@ -538,7 +538,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) { ...@@ -538,7 +538,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) {
default: default:
invariant(sourceType, (sourceType)=>`Unknown source type: ${sourceType}`); invariant(sourceType, (sourceType)=>`Unknown source type: ${sourceType}`);
} }
throw new Error(`Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`); return `Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available.`;
} }
function loadChunk(chunkData) { function loadChunk(chunkData) {
return loadChunkInternal(1, this.m.id, chunkData); return loadChunkInternal(1, this.m.id, chunkData);
...@@ -819,7 +819,7 @@ function instantiateModule(moduleId, sourceType, sourceData) { ...@@ -819,7 +819,7 @@ function instantiateModule(moduleId, sourceType, sourceData) {
// This can happen if modules incorrectly handle HMR disposes/updates, // This can happen if modules incorrectly handle HMR disposes/updates,
// e.g. when they keep a `setTimeout` around which still executes old code // e.g. when they keep a `setTimeout` around which still executes old code
// and contains e.g. a `require("something")` call. // and contains e.g. a `require("something")` call.
factoryNotAvailable(id, sourceType, sourceData); throw new Error(factoryNotAvailableMessage(id, sourceType, sourceData) + ' It might have been deleted in an HMR update.');
} }
const hotData = moduleHotData.get(id); const hotData = moduleHotData.get(id);
const { hot, hotState } = createModuleHot(id, hotData); const { hot, hotState } = createModuleHot(id, hotData);
...@@ -1834,5 +1834,5 @@ chunkListsToRegister.forEach(registerChunkList); ...@@ -1834,5 +1834,5 @@ chunkListsToRegister.forEach(registerChunkList);
})(); })();
//# debugId=9cf0cfff-fe6b-e2a6-ed5a-275f25467c66 //# debugId=8faf1c28-5e36-9739-d4ef-60847ff8a1f3
//# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js.map //# sourceMappingURL=aaf3a_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js.map
\ No newline at end of file
...@@ -522,7 +522,7 @@ const moduleFactories = new Map(); ...@@ -522,7 +522,7 @@ const moduleFactories = new Map();
contextPrototype.M = moduleFactories; contextPrototype.M = moduleFactories;
const availableModules = new Map(); const availableModules = new Map();
const availableModuleChunks = new Map(); const availableModuleChunks = new Map();
function factoryNotAvailable(moduleId, sourceType, sourceData) { function factoryNotAvailableMessage(moduleId, sourceType, sourceData) {
let instantiationReason; let instantiationReason;
switch(sourceType){ switch(sourceType){
case 0: case 0:
...@@ -537,7 +537,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) { ...@@ -537,7 +537,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) {
default: default:
invariant(sourceType, (sourceType)=>`Unknown source type: ${sourceType}`); invariant(sourceType, (sourceType)=>`Unknown source type: ${sourceType}`);
} }
throw new Error(`Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`); return `Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available.`;
} }
function loadChunk(chunkData) { function loadChunk(chunkData) {
return loadChunkInternal(1, this.m.id, chunkData); return loadChunkInternal(1, this.m.id, chunkData);
...@@ -818,7 +818,7 @@ function instantiateModule(moduleId, sourceType, sourceData) { ...@@ -818,7 +818,7 @@ function instantiateModule(moduleId, sourceType, sourceData) {
// This can happen if modules incorrectly handle HMR disposes/updates, // This can happen if modules incorrectly handle HMR disposes/updates,
// e.g. when they keep a `setTimeout` around which still executes old code // e.g. when they keep a `setTimeout` around which still executes old code
// and contains e.g. a `require("something")` call. // and contains e.g. a `require("something")` call.
factoryNotAvailable(id, sourceType, sourceData); throw new Error(factoryNotAvailableMessage(id, sourceType, sourceData) + ' It might have been deleted in an HMR update.');
} }
const hotData = moduleHotData.get(id); const hotData = moduleHotData.get(id);
const { hot, hotState } = createModuleHot(id, hotData); const { hot, hotState } = createModuleHot(id, hotData);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment