Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.16k stars 1.17k forks source link

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

Open L422Y opened 1 year ago

L422Y commented 1 year ago

Issue

Nuxt development server hot-reload causing error when using in Nuxt (3) server-side plugin/module 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.

✔ 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, 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:

    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

mrchoke commented 7 months ago

Nowadays still have same issued .