diff --git a/packages/kit/src/config/env.ts b/packages/kit/src/config/env.ts index f2ad896f89..5d8dd87b9b 100644 --- a/packages/kit/src/config/env.ts +++ b/packages/kit/src/config/env.ts @@ -1,4 +1,4 @@ -import { existsSync, promises as fsp } from 'fs' +import { promises as fsp, existsSync } from 'fs' import { resolve } from 'pathe' import dotenv from 'dotenv' import { LoadNuxtConfigOptions } from './load' diff --git a/packages/kit/src/config/load.ts b/packages/kit/src/config/load.ts index 9d6f93175d..1e5d5b4ecb 100644 --- a/packages/kit/src/config/load.ts +++ b/packages/kit/src/config/load.ts @@ -22,9 +22,11 @@ export interface LoadNuxtConfigOptions { } } -export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions { +export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise { const rootDir = resolve(process.cwd(), opts.rootDir || '.') + await loadEnv(rootDir, opts.envConfig) + const nuxtConfigFile = tryResolveModule(resolve(rootDir, opts.configFile || 'nuxt.config')) let nuxtConfig: any = {} @@ -50,8 +52,6 @@ export function loadNuxtConfig (opts: LoadNuxtConfigOptions): NuxtOptions { nuxtConfig.rootDir = rootDir } - loadEnv(rootDir, opts.envConfig) - // Resolve and apply defaults return applyDefaults(nuxtConfigSchema, nuxtConfig) as NuxtOptions } diff --git a/packages/nuxt3/src/core/nuxt.ts b/packages/nuxt3/src/core/nuxt.ts index 63d9aebaca..024b155800 100644 --- a/packages/nuxt3/src/core/nuxt.ts +++ b/packages/nuxt3/src/core/nuxt.ts @@ -64,7 +64,7 @@ async function initNuxt (nuxt: Nuxt) { } export async function loadNuxt (opts: LoadNuxtOptions): Promise { - const options = loadNuxtConfig(opts) + const options = await loadNuxtConfig(opts) // Temp options.appDir = options.alias['#app'] = resolve(distDir, 'app')