diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index 505003dc45..6da840d29b 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -25,20 +25,6 @@ export default defineNuxtCommand({ async invoke (args, options = {}) { overrideEnv('development') - const { listen } = await import('listhen') - const { toNodeListener } = await import('h3') - let currentHandler: RequestListener | undefined - let loadingMessage = 'Nuxt is starting...' - const loadingHandler: RequestListener = async (_req, res) => { - const { loading: loadingTemplate } = await importModule('@nuxt/ui-templates') - res.setHeader('Content-Type', 'text/html; charset=UTF-8') - res.statusCode = 503 // Service Unavailable - res.end(loadingTemplate({ loading: loadingMessage })) - } - const serverHandler: RequestListener = (req, res) => { - return currentHandler ? currentHandler(req, res) : loadingHandler(req, res) - } - const rootDir = resolve(args._[0] || '.') showVersions(rootDir) @@ -55,6 +41,20 @@ export default defineNuxtCommand({ } }) + const { listen } = await import('listhen') + const { toNodeListener } = await import('h3') + let currentHandler: RequestListener | undefined + let loadingMessage = 'Nuxt is starting...' + const loadingHandler: RequestListener = async (_req, res) => { + const { loading: loadingTemplate } = await importModule('@nuxt/ui-templates', config.modulesDir) + res.setHeader('Content-Type', 'text/html; charset=UTF-8') + res.statusCode = 503 // Service Unavailable + res.end(loadingTemplate({ loading: loadingMessage })) + } + const serverHandler: RequestListener = (req, res) => { + return currentHandler ? currentHandler(req, res) : loadingHandler(req, res) + } + const listener = await listen(serverHandler, { showURL: false, clipboard: args.clipboard, diff --git a/packages/nuxi/src/utils/esm.ts b/packages/nuxi/src/utils/esm.ts index a03ed1a057..38cc1f1fa7 100644 --- a/packages/nuxi/src/utils/esm.ts +++ b/packages/nuxi/src/utils/esm.ts @@ -7,7 +7,7 @@ export async function tryResolveModule (id: string, url = import.meta.url) { } catch { } } -export async function importModule (id: string, url = import.meta.url) { +export async function importModule (id: string, url: string | string[] = import.meta.url) { const resolvedPath = await resolvePath(id, { url }) return import(pathToFileURL(resolvedPath).href).then(interopDefault) }