diff --git a/src/assets.ts b/src/assets.ts index f62fc15..8a7e3d9 100644 --- a/src/assets.ts +++ b/src/assets.ts @@ -1,6 +1,6 @@ import * as path from 'node:path'; import { cwd } from 'node:process'; -import { stat, readFile, writeFile, mkdir } from 'node:fs/promises'; +import { stat } from 'node:fs/promises'; import { getVideoConfig } from './config.js'; import { deepMerge, camelCase, isRemote, toSafePath } from './utils/utils.js'; import * as transformers from './providers/transformers.js'; diff --git a/src/config.ts b/src/config.ts index 3f747f6..4b9e31a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,14 +1,10 @@ import { cwd } from 'node:process'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; -import nextConfig from 'next/config.js'; import type { NextConfig } from 'next'; import { Asset } from './assets'; import { mkdir, readFile, writeFile } from 'node:fs/promises'; -// @ts-ignore -const getConfig = nextConfig.default; - /** * Video configurations */ @@ -101,21 +97,20 @@ export const videoConfigDefault: VideoConfigComplete = { /** * The video config is set in `next.config.js` and passed to the `withNextVideo` function. * The video config is then stored in `serverRuntimeConfig`. + * Import `next.config.js` ourselves because Next.js serializes the config and + * we need the raw object with functions. */ export async function getVideoConfig(): Promise { - let nextConfig: NextConfig | undefined = getConfig(); - if (!nextConfig?.serverRuntimeConfig?.nextVideo) { + let nextConfig: NextConfig | undefined; + try { + nextConfig = await importConfig('next.config.js'); + } catch (err) { try { - nextConfig = await importConfig('next.config.js'); - } catch (err) { - try { - nextConfig = await importConfig('next.config.mjs'); - } catch { - console.error('Failed to load next-video config.'); - } + nextConfig = await importConfig('next.config.mjs'); + } catch { + console.error('Failed to load next-video config.'); } } - return nextConfig?.serverRuntimeConfig?.nextVideo; }