Skip to content

TypeError: Invalid URL #661

@fa0311

Description

@fa0311

Bug report

Description / Observed Behavior

When importing the @vercel/og module, an error occurs during the module's initialization in a GitHub Actions environment. The error appears to be related to converting a file path to a URL for the bundled font file (noto-sans-v27-latin-regular.ttf). This issue does not occur on my Japanese Windows machine but consistently reproduces on GitHub Actions using various Node.js versions (e.g., lts/-1, lts/*, latest).

The error log includes the following message:

TypeError: Invalid URL
    at new URL (node:internal/url:806:29)
    at fileURLToPath (node:internal/url:1485:12)
    at file:///D:/a/satiri-test/satiri-test/node_modules/@vercel/og/dist/index.node.js:18929:32
    ...
    input: '.\\file:\\D:\\a\\satiri-test\\satiri-test\\node_modules\\@vercel/og\\dist\\noto-sans-v27-latin-regular.ttf'

Expected Behavior

I expect @vercel/og to correctly resolve and load its assets (like fonts) without errors, regardless of the environment. The module should work seamlessly both locally and in CI environments such as GitHub Actions.

Reproduction

The issue can be reproduced with the following code:

import fs from "node:fs/promises";
import { ImageResponse } from "@vercel/og";
import component from "./component";

(async () => {
  const response = new ImageResponse(component(), {
    width: 800,
    height: 600,
  });
  await fs.writeFile("out.png", Buffer.from(await response.arrayBuffer()));
})();

To reproduce:

  1. Clone the repository: https://github.com/fa0311/satori-test
  2. Run the code with:
    node --loader ts-node/esm src/main.ts

or

  1. Observe the error in the GitHub Actions logs: GitHub Actions Run

Additional Context

  • @vercel/og version: 0.6.5
  • React version: 19.0.0
  • Node.js version: Tested with v20.18.2 and others
  • Environment: The issue occurs in GitHub Actions (CI), while it does not on my local Japanese Windows environment.
  • Additional Note: There is an experimental warning related to the --experimental-loader flag, and the error seems to be triggered during the import stage when resolving the font file URL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions