If you prefer not to use the automatic init, follow these steps to manually integrate next-video into your Next.js project.
1. Install the package
# NPM
npm install next-video
# Yarn
yarn add next-video
# pnpm
pnpm add next-video
2. Create the videos directory
Create a /videos directory in your project root to store source files:
mkdir videos
Add these lines to your .gitignore to keep large video files out of git while tracking their JSON metadata:
# next-video
videos/*
!videos/*.json
!videos/*.js
!videos/*.ts
public/_next-video
3. Update Next.js configuration
Wrap your Next.js configuration with withNextVideo from next-video/process.
For CommonJS (next.config.js):
const { withNextVideo } = require('next-video/process');
/** @type {import('next').NextConfig} */
const nextConfig = {};
module.exports = withNextVideo(nextConfig);
For ES Modules (next.config.mjs):
import { withNextVideo } from 'next-video/process';
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default withNextVideo(nextConfig);
4. Add video import types (TypeScript only)
Create a video.d.ts file in your project root:
/// <reference types="next-video/video-types/global" />
Add this file to the include array in your tsconfig.json:
{
"include": ["video.d.ts", "next-env.d.ts", /* ... */ ]
}
Note for Turbopack users: You must add a path alias to tsconfig.json so /videos imports resolve correctly:
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"],
"@videos/*": ["./videos/*"]
}
}
}
5. Update dev script
Add the watch command to your package.json to sync videos during development:
"scripts": {
"dev": "next dev & npx next-video sync -w"
}
6. Sync videos
To upload and process a video file (e.g., videos/sample-video.mp4), run:
npx next-video sync