@napi-rs/canvas 1.0.12 silently ignores unquoted font names in ctx.font
Starting with @napi-rs/canvas 1.0.12, a font set as ctx.font = '48px M PLUS Rounded 1c' — without quotes around the family name — is silently ignored: Japanese text renders as 10px tofu[1], with no exception or warning, and toBuffer() still returns an image. The author of makeitaquote, an npm library that draws "Make it a Quote"-style images for a Discord bot, hit this after reinstalling dependencies: its package.json allowed "^1.0.8" and the lockfile pinned 1.0.8, so CI kept passing, but users running npm install got 1.0.13. Swapping versions one by one showed that 1.0.11 (published 2026-10-10) renders unquoted names, while 1.0.12 (2026-10-20) and 1.0.13 (2026-10-21) ignore them; the result was the same on Windows 11 and on WSL Ubuntu 24.04, both on Node.js 24.
The cause is PR #1381, which makes ctx.font parsing, font selection, text layout and measureText match Blink[2] in Chrome 155; the release note says only "fix(canvas): parse fonts, lay out and measure text like Blink", and the PR states that CSS-invalid font values are ignored and calls the changes non-breaking. In CSS, an unquoted family name is a sequence of CSS identifiers[3], and identifiers cannot start with a digit, so the "1c" in M PLUS Rounded 1c makes the whole value invalid; the author reproduced the same behavior in Chromium 156 (Brave), meaning browser canvas always worked this way. Names containing digit-initial words fail (M PLUS 1p, Font Awesome 6 Free, O'Brien Sans), while Noto Sans JP, DotGothic16 and Japanese names pass. The same release made font-weight work on the wght axis of variable fonts[4] (PR #1165); out of 142 sample images from makeitaquote, 47 were pixel-identical and the rest differed by 0.1% to 1.85%.
The fixes are to quote family names in ctx.font (leaving generic families like sans-serif unquoted), to read ctx.font back in tests to catch silently dropped values, or to pin ">=1.0.8 <1.0.12"; makeitaquote 12.1.4 added quoting and the pin, and 12.1.5 moved to "^1.0.13". The author agrees with the move toward browser compatibility but calls this an effective breaking change for anyone drawing Japanese text: a patch update broke the M PLUS family with no exception, no warning and no hint in the release note.
Sources
-
JPZenn JA
@napi-rs/canvas v1.0.12 で実質的な破壊的変更が入った話





