File size: 2,101 Bytes
94786da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
diff --git a/packages/next/src/server/route-modules/app-route/module.ts b/packages/next/src/server/route-modules/app-route/module.ts
index 3718f09b25..d8c4820dd4 100644
--- a/packages/next/src/server/route-modules/app-route/module.ts
+++ b/packages/next/src/server/route-modules/app-route/module.ts
@@ -235,6 +235,9 @@ export class AppRouteRouteModule extends RouteModule<
   // Non-null while an async userland module (top-level await) is loading.
   // ensureUserland() awaits this before the first request is handled.
   private _pendingUserland: Promise<void> | null = null
+  // Init error from an async userland module, rethrown by ensureUserland().
+  private _initError: unknown = null
+  private _hasInitError = false
   // Synchronous per-request userland getter for Turbopack dev mode.
   // Called on every request to pick up server HMR updates.
   private readonly _getUserland?: () => AppRouteUserlandModule
@@ -252,7 +255,12 @@ export class AppRouteRouteModule extends RouteModule<
         this._pendingUserland = result.then((mod) => {
           this._userland = mod
           this._pendingUserland = null
-          this._initFromUserland()
+          try {
+            this._initFromUserland()
+          } catch (err) {
+            this._initError = err
+            this._hasInitError = true
+          }
         })
       } else {
         this._userland = result
@@ -275,6 +283,9 @@ export class AppRouteRouteModule extends RouteModule<
     if (this._pendingUserland) {
       await this._pendingUserland
     }
+    if (this._hasInitError) {
+      throw this._initError
+    }
   }
 
   constructor({
@@ -312,7 +323,12 @@ export class AppRouteRouteModule extends RouteModule<
         this._pendingUserland = result.then((mod) => {
           this._userland = mod
           this._pendingUserland = null
-          this._initFromUserland()
+          try {
+            this._initFromUserland()
+          } catch (err) {
+            this._initError = err
+            this._hasInitError = true
+          }
         })
       } else {
         this._userland = result