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

SyntaxError: Named export 'fromBuffer' not found. #86

Closed
boringContributor opened this issue Feb 18, 2023 · 6 comments · Fixed by #87
Closed

SyntaxError: Named export 'fromBuffer' not found. #86

boringContributor opened this issue Feb 18, 2023 · 6 comments · Fixed by #87

Comments

@boringContributor
Copy link

Hey there,

first off all BIG thanks for this project. I made a video streaming backend and created the requests manually, but switched now to your client as it makes my life much easier.

However, I'm having a problem:

I'm using NextJS (13.1.6) API routes and get the following error:

image

My code looks like this:

export default withUserGuard(async function handler(req, res) {
    if (req.method !== 'GET') {
        res.setHeader("Allow", ["GET"]);
        return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
    }
    try {
        const mostRecent = await getMostRecentVideos();
        return res.status(200).json({ mostRecent });
    } catch (e) {
        return res.status(500).end();
    }
});

const getMostRecentVideos = async () => {
    const videos = await stream.listVideos({
        page: 1,
        itemsPerPage: 10,
        orderBy: 'date'
    })

    return videos.items.map((video) => ({
        viewTime: prettyPrintSeconds(video.length),
        collection: collectionIdToGenre.get(video.collectionId),
        ...video,
    }));
};

Do you have an idea how to solve that or is there a way to allow CommonJS modules properly?
Thanks and all the best!

@boringContributor
Copy link
Author

I checked your code and tried the following:

image

so there is an issue somewhere. If you have an idea -> great, if not I'd think about it and contribute when I found the issue :)

@Abdulazeez-98
Copy link
Contributor

I checked your code and tried the following:

image

so there is an issue somewhere. If you have an idea -> great, if not I'd think about it and contribute when I found the issue :)

try fileType.fromBuffer() this would theoretically solve the issue. I will create a pull request regarding this.

@boringContributor
Copy link
Author

@Abdulazeez-98 yes the screenshot above is of the npm package. I modified it and it worked so yeah not sure why it bundles it like that but it does not work. Thanks for the PR!

@Abdulazeez-98
Copy link
Contributor

@boringContributor
You're welcome 👍
The library "file-type" doesn't export individual objects because it only supports CommonJS (or at least that's my understanding). So we need to import the whole thing and then call the function fromBuffer().
This is a limitation in the "file-type" library for not supporting ESM imports. There's a new version of this library but it only supports ESM and not CommonJS. Most NPM libraries support both module systems.

@dan-online
Copy link
Owner

Ah yes the usual discrepancies between cjs and esm, personally I promote the use of esm for everything but I understand why you would need a cjs bundle. Tad annoying that libraries like this don't support both 😕

Thanks @Abdulazeez-98 for the PR, I'll test it and get that merged if everything looks good

@dan-online
Copy link
Owner

Published in bunnycdn-stream@2.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants