music-metadata: musicMetadata.parseFile is not a function

Is there an existing issue for this?

  • I have searched the existing issues

music-metadata version

10.7.0

Current Behavior

Error using parseFile musicMetadata.parseFile is not a function

code:

import {parseFile} from "music-metadata";

async function cacheSender(filePath, event, channel) {
  const metadata = await parseFile(filePath, {skipPostHeaders: true, includeChapters: false});
  event.sender.send(channel, {
    audio_id: filePath,
    title: metadata.common.title ? metadata.common.title : path.basename(filePath, path.extname(filePath)),
    artist: metadata.common.artist,
    album: metadata.common.album,
    numberOfChannels: metadata.format.numberOfChannels,//声道
    sampleRate: metadata.format.sampleRate,//音频采样率
    duration: metadata.format.duration,//时长 s
    formatTime: metadata.format.duration ? Math.floor(metadata.format.duration / 60).toString().padStart(2, '0') + ':' + Math.floor(metadata.format.duration % 60).toString().padStart(2, '0') : '?',
    bitrate: metadata.format.bitrate,//比特率
    path: filePath,
    isLike: false
  })
}

An error occurs when calling this code

Expected Behavior

No response

Attached audio sample?

  • I have provided sufficient information to reproduce the issue

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

This is still an issue with v11 and TypeScript. The above solutions all yield the same result.

Module '"music-metadata"' has no exported member 'parseFile'.

I can @ts-expect-error the error and the function works, so it’s just an issue with the exported types.

Can you please raise that as a new issue @lowvisiondave , and include the following information:

  • Your TypeScript configuration
  • Module type (commonjs / ESM)
  • Front-end / back-end usage
  • Node.js version, if used

Minimum reproducable code if possible.

esm 导入