muxinc / next-video

The easiest way to add video in your Nextjs app.
https://next-video.dev
MIT License
853 stars 32 forks source link

npx next-video sync throwing error: can't read next config file #300

Closed nmndwivedi closed 2 months ago

nmndwivedi commented 2 months ago

Trying to sync the videos in my next js project to mux Im getting the following error

→ npx next-video sync
+ Found 1 unprocessed video
- Processing file: vid1.mp4
Failed to load next-video config.
✗ An unknown error occurred TypeError: Cannot read properties of undefined (reading 'provider')
    at createAsset (file:///Users/namandwivedi/Light/dutch/node_modules/.pnpm/next-video@1.2.0_@types+react-dom@18.3.0_@types+react@18.3.5_next@14.2.8_react-dom@18.3.1_react@18.3.1/node_modules/next-video/dist/assets.js:37:27)
    at async newFileProcessor (file:///Users/namandwivedi/Light/dutch/node_modules/.pnpm/next-video@1.2.0_@types+react-dom@18.3.0_@types+react@18.3.5_next@14.2.8_react-dom@18.3.1_react@18.3.1/node_modules/next-video/dist/cli/sync.js:62:24)
    at async Promise.all (index 0)
    at async Object.handler (file:///Users/namandwivedi/Light/dutch/node_modules/.pnpm/next-video@1.2.0_@types+react-dom@18.3.0_@types+react@18.3.5_next@14.2.8_react-dom@18.3.1_react@18.3.1/node_modules/next-video/dist/cli/sync.js:88:24)

Looking into the source of the error it is coming from this function in config.js in next-video package

async function getVideoConfig() {
  let nextConfig2 = getConfig();
  if (!nextConfig2?.serverRuntimeConfig?.nextVideo) {
    try {
      nextConfig2 = await importConfig("next.config.js");
    } catch (err) {
      try {
        nextConfig2 = await importConfig("next.config.mjs");
      } catch {
        console.error("Failed to load next-video config.");
      }
    }
  }
  return nextConfig2?.serverRuntimeConfig?.nextVideo;
} 

The config isnt being loaded. Is anyone else facing this issue?

Versions: "next": "14.2.8", "next-video": "^1.2.0",

nmndwivedi commented 2 months ago

Ok fixed it by changing require to import in next config

const { withNextVideo } = require("next-video/process");

needed to be

import { withNextVideo } from "next-video/process";

Taloqq commented 4 weeks ago

Having same problem and changing the require to import didnt work for me, using nextjs 15

Fixed: next.config,ts needed to be next.config.mjs