@@ -9,16 +9,18 @@ import type { AddressInfo } from 'node:net'
99import EventEmitter from 'node:events'
1010import { existsSync , watch } from 'node:fs'
1111import { mkdir } from 'node:fs/promises'
12-
1312import process from 'node:process'
13+ import { pathToFileURL } from 'node:url'
14+
1415import defu from 'defu'
16+ import { resolveModulePath } from 'exsolve'
1517import { toNodeListener } from 'h3'
1618import { listen } from 'listhen'
1719import { resolve } from 'pathe'
1820import { debounce } from 'perfect-debounce'
1921import { provider } from 'std-env'
20-
2122import { joinURL } from 'ufo'
23+
2224import { clearBuildDir } from '../utils/fs'
2325import { loadKit } from '../utils/kit'
2426
@@ -162,20 +164,12 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
162164 renderError ( req , res , this . _loadingError )
163165 }
164166
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-
173167 async _renderLoadingScreen ( req : IncomingMessage , res : ServerResponse ) {
174168 res . statusCode = 503
175169 res . setHeader ( 'Content-Type' , 'text/html' )
176170 const loadingTemplate = this . options . loadingTemplate
177171 || this . _currentNuxt ?. options . devServer . loadingTemplate
178- || await this . resolveLoadingTemplate ( )
172+ || await resolveLoadingTemplate ( this . cwd )
179173 res . end (
180174 loadingTemplate ( {
181175 loading : this . _loadingMessage || 'Loading...' ,
@@ -434,3 +428,12 @@ function createConfigDirWatcher(cwd: string, onReload: (file: string) => void) {
434428
435429 return ( ) => configDirWatcher . close ( )
436430}
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