Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musicMetadata.parseFile is not a function #2328

Closed
2 tasks done
Empty-57 opened this issue Jan 17, 2025 · 14 comments
Closed
2 tasks done

musicMetadata.parseFile is not a function #2328

Empty-57 opened this issue Jan 17, 2025 · 14 comments
Labels
bug Bug, will addressed with high priority

Comments

@Empty-57
Copy link

Empty-57 commented Jan 17, 2025

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
@Empty-57 Empty-57 added the bug Bug, will addressed with high priority label Jan 17, 2025
@Empty-57
Copy link
Author

esm 导入

@jcalfee
Copy link

jcalfee commented Jan 22, 2025

Same issue ^10.7.0

Image

This is documented in API section at npmjs.

@Empty-57
Copy link
Author

Same issue ^10.7.0 相同问题 ^10.7.0

Image

This is documented in API section at npmjs.这记录在 npmjs 的 API 部分。

问题已解决了,将整个项目模块作为esm导入就行了

@jcalfee
Copy link

jcalfee commented Jan 22, 2025

This import works for functionality but the typescript is off:

import * as mm from 'music-metadata'
const {parseFile} = mm

I'm running this under a bash file as follows:

#!/usr/bin/env jiti
// ...

see jiti

The complexity of all this is beyond me, but the author of unjs has many projects with imports. I noticed they all seam to have some sort of build step though.

@jcalfee
Copy link

jcalfee commented Jan 22, 2025

Actually, import {parseFile} from 'music-metadata' works as well. It is only typescript that is not working. I'm using vscodium..

@Empty-57
Copy link
Author

Empty-57 commented Jan 22, 2025 via email

@jcalfee
Copy link

jcalfee commented Jan 22, 2025

Thank you.. All your replies look like this to me:

Image

But I can read the post at the top.

Yes, I do have "type": "module" in my package.json and I made sure to Restart the TS Server. What is interesting is, it is not all methods:

Image

@Empty-57
Copy link
Author

Empty-57 commented Jan 22, 2025 via email

@Empty-57
Copy link
Author

Empty-57 commented Jan 22, 2025 via email

@Empty-57
Copy link
Author

Empty-57 commented Jan 22, 2025 via email

@jcalfee
Copy link

jcalfee commented Jan 22, 2025

The error is:

Module '"music-metadata"' has no exported member 'parseFile'.ts(2305)
import parseFile

I removed node_modules then re-installed via pnpm install..

@Empty-57
Copy link
Author

Empty-57 commented Jan 22, 2025 via email

@jcalfee
Copy link

jcalfee commented Jan 23, 2025

It is not exported .. I can use F12 and vscodium brings me to this file under the current project's folder / node_modules:

Image

You can see parseWebStream is right under parseBlob, but parseStream is not here.

@Borewit
Copy link
Owner

Borewit commented Jan 23, 2025

For importing music-metadata in a CommonJS / TypeScript project, check: music-metadata README: CommonJS backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, will addressed with high priority
Projects
None yet
Development

No branches or pull requests

3 participants