79517384

Date: 2025-03-18 12:20:21
Score: 1
Natty:
Report link

I had a similar issue. In my case, Japanese fonts were not showing up in screenshots when using @sparticuz/chromium and puppeteer-core. I’m also using Next.js and deploying to Vercel.

I tried solutions like await chromium.font([font file URL]) or loading the font file the way you described, but they didn't work.

Here’s how I solved it:

  1. Place your font file in the project root like this:
(root directory)
- fonts
  - NotoSansJP-Regular.ttf
- src
- public
  1. Add this to your next.config.js to make sure the font is included in the serverless bundle:
const nextConfig = {
  experimental: {
    outputFileTracingIncludes: {
      '**': ['./fonts/**/*']
    }
  }
};

module.exports = nextConfig;
  1. In your code, load the font from the filesystem:
import fs from "fs";
import path from "path";

const fontPath = path.join(process.cwd(), "fonts", "NotoSansJP-Regular.ttf");
chromium.font(fontPath);

const browser = await puppeteerLib.launch({
  args: [...chromium.args, "--no-sandbox", "--disable-setuid-sandbox"],
  defaultViewport: chromium.defaultViewport,
  executablePath: await chromium.executablePath(),
  headless: chromium.headless,
});

I hope it will work. For more details on including files in Vercel functions, see:
👉 How can I use files in Vercel Functions?

Reasons:
  • Blacklisted phrase (0.5): How can I
  • Whitelisted phrase (-2): I solved
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Looks like a comment (1):
  • Low reputation (1):
Posted by: EI1024