Plaiceholder Issues with Remote blurDataUrl
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hi Team
This is my tach stack
"@plaiceholder/next": "^3.0.0",
"next": "^14.0.1",
"plaiceholder": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sharp": "^0.32.6",
I'm trying to get the images to blur on load, ideally at built time.
Based on the docs
https://nextjs.org/docs/app/api-reference/components/image#placeholder
NextJs is recommending to use Plaiceholder to generate the base64 URL
Following the Plaiceholder docs as well
https://plaiceholder.co/docs
Files
The image attached is the error generated from this file
I have also read this feed which is the same set up with a different error..
https://nextjs-forum.com/post/1174662696512274502#message-1174662696512274502
Has anyone experienced this problem?
I'd really appreciate any help on this topic
This is my tach stack
"@plaiceholder/next": "^3.0.0",
"next": "^14.0.1",
"plaiceholder": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sharp": "^0.32.6",
I'm trying to get the images to blur on load, ideally at built time.
Based on the docs
https://nextjs.org/docs/app/api-reference/components/image#placeholder
NextJs is recommending to use Plaiceholder to generate the base64 URL
Following the Plaiceholder docs as well
https://plaiceholder.co/docs
Files
// next.config.mjs
// @ts-check
import withPlaiceholder from "@plaiceholder/next";
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
images: {
deviceSizes: [376, 480, 600, 768, 900, 1024, 1200, 1300],
formats: ['image/webp'],
remotePatterns: [
{
protocol: 'https',
hostname: 'media.graphcms.com',
pathname: '**',
},
{
protocol: 'https',
hostname: 'media.graphassets.com',
pathname: '**',
}
],
}
}
export default withPlaiceholder(nextConfig);// @/utils/useBlurImageData.ts
import { getPlaiceholder } from "plaiceholder";
export default async function useBlurImageData(imageUrl: string) {
try {
const buffer = await fetch(imageUrl).then(async (res) => {
return Buffer.from(await res.arrayBuffer());
});
const { base64 } = await getPlaiceholder(buffer);
return base64;
} catch (err) {
err;
}
}The image attached is the error generated from this file
.next/static/chunks/app/events/page.js"use strict";
module.exports = require("sharp");I have also read this feed which is the same set up with a different error..
https://nextjs-forum.com/post/1174662696512274502#message-1174662696512274502
Has anyone experienced this problem?
I'd really appreciate any help on this topic
16 Replies
Yeah I got that same error when using placieholder, it returned the data URLs correctly though, just wouldn't build, so for my use case I just had two dynamic images so I just manually inputted those data URLs conditionally, obviously that's not feasible when you have a ton of dynamic images, but, the package seems to not work out of the box with next.
Brown bearOP
I'm so glad to hear you had the same issues I thought I was missing something.
However in the thread I listed they have the same package versions and they are saying it's working for them so I'm confused.
I have a lot of dynamic images so I need to figure this out unfortunately
However in the thread I listed they have the same package versions and they are saying it's working for them so I'm confused.
I have a lot of dynamic images so I need to figure this out unfortunately
Well one thing I did figure out is, the reason require is undefined is because the @plaiceholder/next package requires that the next.config.js become a CommonJS module instead of ESM, so if it's still ESM then require will be undefined, but, when I switch my next.config.js to .mjs and switched the imports with requires in there, my whole app broke.
So I gave up on it.
Brown bearOP
I tried that as well 😂
I'm sure there is away around this surely we aren't the only ones with this issue.
I am considering using Next13 instead however then you loose all the new features.
I'm sure there is away around this surely we aren't the only ones with this issue.
I am considering using Next13 instead however then you loose all the new features.
What are you using to manually degerate the base64 URLS?
I tried it before Next.js 14 was a thing.
I used plaiceholder, if you console.log the base64 you'll get the correct values
Brown bearOP
So you had the same issue in Next 13..
Well at least you saved me that experience
Well at least you saved me that experience
so I just extracted those lol
Brown bearOP
Thanks Plague
Yeah np, I hope someone has a solution for this, cause it would be nice to have truely dynamic image blurs
Brown bearOP
Especially when NextJS promotes Plaiceholder
i just noticed that if we are using a client component and the image component is a child of such client component, it would throw require error. else it does not
plaiceholder although it claims to be complete, seems to face issues with app router now.
we can no longer use any client features along with it