microsoft / microsoft/monaco-editor

[Bug] FontFace API loads codicon font from hardcoded ESM source path at runtime, bypassing bundler asset processing

Open
#5,252 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

No response

Monaco Editor Playground Code

Reproduction Steps

No response

Actual (Problematic) Behavior

When bundling Monaco Editor with esbuild (or similar bundlers), the codicon font is correctly handled via CSS @font-face when using a file loader. However, Monaco also loads the font programmatically at runtime via the FontFace API using a hardcoded path that reflects the original ESM module structure:

/base/browser/ui/codicons/codicon/codicon.ttf

This path is a string literal inside JS, so bundlers cannot rewrite it during the build — only url() references in CSS and static import/require calls are processed. The result is a 404 request at runtime, visible in DevTools with initiator other (indicating a CSS-via-JS FontFace call).
Steps to reproduce

Bundle Monaco Editor ESM with esbuild using loader: { ".ttf": "file" }
Set publicPath or rely on relative paths for font resolution
Open the app in a browser and inspect the Network tab

Expected Behavior

The font URL used in the FontFace API call should either:

Use a path resolvable at runtime (e.g. relative to the script), or
Be configurable via MonacoEnvironment, similar to worker URLs

Additional Context

A request is made to /base/browser/ui/codicons/codicon/codicon.ttf (the raw ESM source path), resulting in a 404. The font still renders correctly if already loaded via CSS, but the spurious request and console error are confusing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the esbuild ESM bundle with the .ttf file loader and inspect the FontFace API request for the codicon font. Trace the runtime URL that produces /base/browser/ui/codicons/codicon/codicon.ttf, then verify the bundled app resolves the font without a 404 and preserves the expected CSS font loading behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.