Using fonts in Next js API route

I’m doing some basic image processing in a Next js API route where I am using sharp to turn svg text to a png. The issue is that the custom font is not being loaded, which seems to be resulting in the error (though this may be unrelated),
Fontconfig error: No writable cache directories. The app is deployed on Vercel.

I am wondering how to load fonts in the public directory in a Next js API route.

I tried using next’s localFont function to load custom fonts but this seems to only work with react components not API routes.

  • What public directory?

    – 

  • @TimRoberts ref

    – 

  • @TimRoberts I think he wants to load a font file contained in his projects public directory into his API route. For some reason.

    – 

  • Clearly, more details are needed. Are you trying to allow the user to UPLOAD fonts in a place where they can be seen? Are you trying to pre-populate a directory with a bunch of fonts?

    – 

  • @FabioNettis what would you recommend?

    – 

Leave a Comment