Skip to content

Commit

Permalink
site: add fixes for Turbopack (#333)
Browse files Browse the repository at this point in the history
luwes authored Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 38effcd commit 6d6e028
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 14 additions & 3 deletions examples/default-provider/app/(default)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname } from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as fs from 'node:fs/promises';

@@ -17,8 +17,19 @@ export const metadata: Metadata = {
'Next Video solves the hard problems with embedding, storing, streaming, and customizing video in your Next.js app.',
};

const fileDir = dirname(fileURLToPath(import.meta.url));
const themeScript = await fs.readFile(`${fileDir}/../theme-toggle.js`, 'utf-8');
// https://francoisbest.com/posts/2023/reading-files-on-vercel-during-nextjs-isr
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const nextJsRootDir = path.resolve(__dirname, '../../')

export function resolve(importMetaUrl: string, ...paths: string[]) {
const dirname = path.dirname(fileURLToPath(importMetaUrl))
const absPath = path.resolve(dirname, ...paths)
// Required for ISR serverless functions to pick up the file path
// as a dependency to bundle.
return path.resolve(process.cwd(), absPath.replace(nextJsRootDir, '.'))
}

const themeScript = await fs.readFile(resolve(import.meta.url, `../theme-toggle.js`), 'utf-8');

export default async function RootLayout({
children,
8 changes: 8 additions & 0 deletions examples/default-provider/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { withNextVideo } from './next-video.mjs';

const fileDir = path.dirname(fileURLToPath(import.meta.url));

/** @type {import('next').NextConfig} */
const nextConfig = (phase, { defaultConfig }) => {
return {
...defaultConfig,
// Needed for Turbopack and symlinking to work
// https://github.com/vercel/next.js/issues/64472#issuecomment-2077483493
// https://nextjs.org/docs/pages/api-reference/config/next-config-js/output#caveats
outputFileTracingRoot: path.join(fileDir, '../../'),
};
};

0 comments on commit 6d6e028

Please sign in to comment.