Repository: vercel/next.js
Pull request: Turbopack: improve missing factory message

Don't mention HMR for prod builds

Changed files:
filename: turbopack/crates/turbopack-ecmascript-runtime/js/src/browser/runtime/base/build-base.ts
patch: @@ -55,7 +55,7 @@ function instantiateModule(
     // This can happen if modules incorrectly handle HMR disposes/updates,
     // e.g. when they keep a `setTimeout` around which still executes old code
     // and contains e.g. a `require("something")` call.
-    factoryNotAvailable(id, sourceType, sourceData)
+    throw new Error(factoryNotAvailableMessage(id, sourceType, sourceData))
   }
 
   const module: Module = createModuleObject(id)

filename: turbopack/crates/turbopack-ecmascript-runtime/js/src/browser/runtime/base/dev-base.ts
patch: @@ -194,7 +194,10 @@ function instantiateModule(
     // This can happen if modules incorrectly handle HMR disposes/updates,
     // e.g. when they keep a `setTimeout` around which still executes old code
     // 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)!

filename: turbopack/crates/turbopack-ecmascript-runtime/js/src/browser/runtime/base/runtime-base.ts
patch: @@ -106,11 +106,11 @@ const availableModules: Map<ModuleId, Promise<any> | true> = new Map()
 
 const availableModuleChunks: Map<ChunkPath, Promise<any> | true> = new Map()
 
-function factoryNotAvailable(
+function factoryNotAvailableMessage(
   moduleId: ModuleId,
   sourceType: SourceType,
   sourceData: SourceData
-): never {
+): string {
   let instantiationReason
   switch (sourceType) {
     case SourceType.Runtime:
@@ -128,9 +128,7 @@ function factoryNotAvailable(
         (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(

filename: turbopack/crates/turbopack-tests/tests/snapshot/debug-ids/browser/output/ba425_crates_turbopack-tests_tests_snapshot_debug-ids_browser_input_index_0151fefb.js
patch: @@ -1,4 +1,4 @@
-;!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([
     "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)"]}
@@ -523,7 +523,7 @@ const moduleFactories = new Map();
 contextPrototype.M = moduleFactories;
 const availableModules = new Map();
 const availableModuleChunks = new Map();
-function factoryNotAvailable(moduleId, sourceType, sourceData) {
+function factoryNotAvailableMessage(moduleId, sourceType, sourceData) {
     let instantiationReason;
     switch(sourceType){
         case 0:
@@ -538,7 +538,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) {
         default:
             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) {
     return loadChunkInternal(1, this.m.id, chunkData);
@@ -819,7 +819,7 @@ function instantiateModule(moduleId, sourceType, sourceData) {
         // This can happen if modules incorrectly handle HMR disposes/updates,
         // e.g. when they keep a `setTimeout` around which still executes old code
         // 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 { hot, hotState } = createModuleHot(id, hotData);
@@ -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
\ No newline at end of file

filename: turbopack/crates/turbopack-tests/tests/snapshot/runtime/default_dev_runtime/output/5c1d0_turbopack-tests_tests_snapshot_runtime_default_dev_runtime_input_index_c0f7e0b0.js
patch: @@ -522,7 +522,7 @@ const moduleFactories = new Map();
 contextPrototype.M = moduleFactories;
 const availableModules = new Map();
 const availableModuleChunks = new Map();
-function factoryNotAvailable(moduleId, sourceType, sourceData) {
+function factoryNotAvailableMessage(moduleId, sourceType, sourceData) {
     let instantiationReason;
     switch(sourceType){
         case 0:
@@ -537,7 +537,7 @@ function factoryNotAvailable(moduleId, sourceType, sourceData) {
         default:
             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) {
     return loadChunkInternal(1, this.m.id, chunkData);
@@ -818,7 +818,7 @@ function instantiateModule(moduleId, sourceType, sourceData) {
         // This can happen if modules incorrectly handle HMR disposes/updates,
         // e.g. when they keep a `setTimeout` around which still executes old code
         // 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 { hot, hotState } = createModuleHot(id, hotData);