'Could not parse custom font file using node-canvas package

I want to use custom font (Inter) with registerFont() function in node-canvas, but i have this error:

Error: Could not parse font file
    at registerFont (<path>)
    (...)

Current code:

const { registerFont, createCanvas } = require('canvas');
registerFont('./public/Inter/static/Inter-Regular.ttf', { family: 'Inter' });

//⚠ canvas must be created after registerFont() 
const canvas = createCanvas(1000, 1000)
const ctx = canvas.getContext('2d')

ctx.font = '150px "Inter"';
// (...)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source