ENOENT: no such file or directory, open ...public when importing static images from public
Unanswered
Britannia Petite posted this in #help-forum
Britannia PetiteOP
We are importing some static images for our OG generation in:
like so:
This works perfectly fine locally.
however in prod on vercel we keep getting some path issues. I tried a lot of think ,simply cannot get it to work:
What is the best and safest way to import these static images from public here? We tried a lot of methods etc. nothing seems to be working....
Thanks for any pointers!!
/apps/storefront/src/app/[countryCode]/opengraph-image.tsx
like so:
readFile(
join(
process.cwd(),
"public",
"test-images",
"og-image-frame-dark.jpg"
)
),
This works perfectly fine locally.
however in prod on vercel we keep getting some path issues. I tried a lot of think ,simply cannot get it to work:
Error: ENOENT: no such file or directory, open '/var/task/apps/storefront/public/test-images/og-image-frame-dark.jpg'
at async f (.next/server/app/[countryCode]/opengraph-image/[__metadata_id__]/route.js:1:2917) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/var/task/apps/storefront/public/test-images/og-image-frame-dark.jpg'
}
What is the best and safest way to import these static images from public here? We tried a lot of methods etc. nothing seems to be working....
Thanks for any pointers!!
9 Replies
Britannia PetiteOP
I changed the import strategy to:
readFile(process.cwd() + "/public/test-images/og-image-frame-dark.jpg")
but I get the same error. I am a bit puzzled whats going on...Britannia PetiteOP
Can anyone help here? Quite a problem for us atm
Keep it simple and not require on any assumption on what the bundler will do
Britannia PetiteOP
not possible... we are building the image from multiple images based on base64
but thanks!
@Britannia Petite We are importing some static images for our OG generation in: `/apps/storefront/src/app/[countryCode]/opengraph-image.tsx`
like so:
readFile(
join(
process.cwd(),
"public",
"test-images",
"og-image-frame-dark.jpg"
)
),
This works perfectly fine locally.
however in prod on vercel we keep getting some path issues. I tried a lot of think ,simply cannot get it to work:
Error: ENOENT: no such file or directory, open '/var/task/apps/storefront/public/test-images/og-image-frame-dark.jpg'
at async f (.next/server/app/[countryCode]/opengraph-image/[__metadata_id__]/route.js:1:2917) {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/var/task/apps/storefront/public/test-images/og-image-frame-dark.jpg'
}
What is the best and safest way to import these static images from public here? We tried a lot of methods etc. nothing seems to be working....
Thanks for any pointers!!
Brown bear
I assume the issue is that this code is happening in a server function rather than in a server component
Your public files are served through an Edge Network so they aren't really on the same FS
Accessing public from a server component should work though