Automattic / Automattic/node-canvas

Error: Could not load font to the system's font host

Open
#2,170 1 comment 4 reactions 0 assignees View on GitHub
Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue

Nuxt development server hot-reload causing error when using in Nuxt (3) server-side plugin/module [nuxt-dsi](https://www.npmjs.com/package/nuxt-dsi) - dev server has to be restarted every time this occurs. Can't seem to catch, handle, or prevent the error in any way.

```shell
✔ Nitro built in 522 ms
ℹ Vite client warmed up in 2684ms
✔ Nitro built in 259 ms
Error: Could not load font to the system's font host
at Object.registerFont (/Users/larry/Development/websites/l422y/nuxt-app/node_modules/canvas/index.js:48:17)
at file:///Users/larry/Development/websites/l422y/nuxt-app/.nuxt/dev/index.mjs:511:27
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Error: Could not load font to the system's font host 00:36:34
at Object.registerFont (/Users/larry/Development/websites/l422y/nuxt-app/node_modules/canvas/index.js:48:17)
at file:///Users/larry/Development/websites/l422y/nuxt-app/.nuxt/dev/index.mjs:511:27
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)

```

## Steps to Reproduce

Create Nuxt (3) app, install the [nuxt-dsi](https://www.npmjs.com/package/nuxt-dsi), module, and setup custom fonts, then start the development server, and modify something within the application (server side) to force a reload.

Example DSI configuration:

```js
dsi: {
fixedText: 'Larry Williamson // Senior Full-Stack Creative Technologist',
path: '/socialImage',
cacheDir: 'dsi-cache',
customHandler: 'lib/dsi-handler.mjs',
fonts: [
{
path: "fonts/Roboto/Roboto-Thin.ttf",
options: {
family: 'robotothin'
}
},
{
path: "fonts/Roboto/Roboto-Regular.ttf",
options: {
family: 'robotoregular'
}
},
{
path: "fonts/Roboto/Roboto-Medium.ttf",
options: {
family: 'robotomedium'
}
}
]
},
```

## Your Environment
```
├── canvas@2.10.2
├─┬ fabric@5.2.4
│ ├── canvas@2.10.2 deduped
│ └─┬ jsdom@19.0.0
│ └── canvas@2.10.2 deduped
└─┬ nuxt-route-meta@2.3.6
└─┬ ast-to-literal@0.0.5
└─┬ jest@25.5.4
└─┬ @jest/core@25.5.4
└─┬ jest-config@25.5.4
└─┬ jest-environment-jsdom@25.5.0
└─┬ jsdom@15.2.1
└── canvas@2.10.2 deduped
```

Node v18.8.0
NPM v8.18.0
macOS 13.0 (22A380)
Apple Silicon M1 Max

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.