Next.js Discord

Discord Forum

ENOENT: no such file or directory, open ...public when importing static images from public

Unanswered
Britannia Petite posted this in #help-forum
Open in Discord
Britannia PetiteOP
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!!

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
Britannia PetiteOP
not possible... we are building the image from multiple images based on base64
but thanks!