fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not resolve "./lib-cov/fluent-ffmpeg" from "./lib-cov/fluent-ffmpeg?commonjs-external"

XIAO-RUI-RUI opened this issue · comments

Error

Could not resolve "./lib-cov/fluent-ffmpeg" from "./lib-cov/fluent-ffmpeg?commonjs-external"
file: ./lib-cov/fluent-ffmpeg?commonjs-external


Environment

win10、node v18.17.1、ts-node v10.9.1、Vite+Vue3。


Files

I use Vue3+Vite init my project, when I import fluent-ffmpeg in electron/main.ts, error opened like this.
electron/main.ts

import { generateFirstFrame } from './VideoProcess.ts'


function handleGenerateFirstFrame(event: Event, videoPath: string): string {
  ***
  generateFirstFrame(videoPath, destSaveImagePath).then(() => {
    console.log('true')
  }).catch(err => {
    console.log(err)
  })
  
  return destSaveImagePath
}

generateFirstFrame() come from electron/VideoProcess.ts

import ffmpeg from 'fluent-ffmpeg'

// ffmpeg.setFfmpegPath('F:/SDK/ffmpeg/bin/ffmpeg.exe')

function generateFirstFrame(videoPath: string, saveImagePath: string): Promise<void> {
  return new Promise<void>(async (resolve, reject) => {
    const [width, height] = await getVideoSize(videoPath)
    
    ffmpeg(videoPath)
      .screenshots({
        timestamps: [1],
        filename: saveImagePath,
        size: `${height}x${width}`
      })
      .on('end', () => {
        resolve()
      })
      .on('error', (err: any) => {
        reject()
      })
    })
}

And my test file is process successfully, but when I use in electron/main.ts, error occours. My VideoProcess.test.ts:

import { generateFirstFrame, getVideoSize } from '../VideoProcess.ts'

const videoPath = 'D:/Video/my-test.mp4'
const outputPath = 'D:/Video/test.png'

generateFirstFrame(videoPath, outputPath).then(() => {
  console.log('true')
}).catch(err => {
  console.log(err)
})

Wish someone help me! Thinks in advance!

I had the exact same issue, but with a different package on my project running Electron+Vite. The issue went away after I followed the instructions for adding the package as a native module: https://www.electronforge.io/config/plugins/vite#native-node-modules