@@ -9,16 +9,18 @@ import type { AddressInfo } from 'node:net'
9
9
import EventEmitter from 'node:events'
10
10
import { existsSync , watch } from 'node:fs'
11
11
import { mkdir } from 'node:fs/promises'
12
-
13
12
import process from 'node:process'
13
+ import { pathToFileURL } from 'node:url'
14
+
14
15
import defu from 'defu'
16
+ import { resolveModulePath } from 'exsolve'
15
17
import { toNodeListener } from 'h3'
16
18
import { listen } from 'listhen'
17
19
import { resolve } from 'pathe'
18
20
import { debounce } from 'perfect-debounce'
19
21
import { provider } from 'std-env'
20
-
21
22
import { joinURL } from 'ufo'
23
+
22
24
import { clearBuildDir } from '../utils/fs'
23
25
import { loadKit } from '../utils/kit'
24
26
@@ -162,20 +164,12 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
162
164
renderError ( req , res , this . _loadingError )
163
165
}
164
166
165
- async resolveLoadingTemplate ( ) {
166
- const { createJiti } = await import ( 'jiti' )
167
- const jiti = createJiti ( this . cwd )
168
- const loading = await jiti . import < { loading : ( ) => string } > ( '@nuxt/ui-templates' ) . then ( r => r . loading ) . catch ( ( ) => { } )
169
-
170
- return loading || ( ( params : { loading : string } ) => `<h2>${ params . loading } </h2>` )
171
- }
172
-
173
167
async _renderLoadingScreen ( req : IncomingMessage , res : ServerResponse ) {
174
168
res . statusCode = 503
175
169
res . setHeader ( 'Content-Type' , 'text/html' )
176
170
const loadingTemplate = this . options . loadingTemplate
177
171
|| this . _currentNuxt ?. options . devServer . loadingTemplate
178
- || await this . resolveLoadingTemplate ( )
172
+ || await resolveLoadingTemplate ( this . cwd )
179
173
res . end (
180
174
loadingTemplate ( {
181
175
loading : this . _loadingMessage || 'Loading...' ,
@@ -434,3 +428,12 @@ function createConfigDirWatcher(cwd: string, onReload: (file: string) => void) {
434
428
435
429
return ( ) => configDirWatcher . close ( )
436
430
}
431
+
432
+ // Nuxt <3.6 did not have the loading template defined in the schema
433
+ export async function resolveLoadingTemplate ( cwd : string ) {
434
+ const nuxtPath = resolveModulePath ( 'nuxt' , { from : cwd , try : true } )
435
+ const uiTemplatesPath = resolveModulePath ( '@nuxt/ui-templates' , { from : nuxtPath || cwd } )
436
+ const r : { loading : ( opts ?: { loading ?: string } ) => string } = await import ( pathToFileURL ( uiTemplatesPath ) . href )
437
+
438
+ return r . loading || ( ( params : { loading : string } ) => `<h2>${ params . loading } </h2>` )
439
+ }
0 commit comments