Skip to content
← Back to Community
Fontconfig error: Cannot load default config file
Profile icon
Trunks8257

Hi, I recently started with repl.it and I'm getting this error while using canvas in node.js. Is there a solution? In the image, all the characters are squares
Thanks in advance

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
enigmaxx1
Profile icon
abdulnaufalpv
Profile icon
hapishanipuddin
Profile icon
Trunks8257
Comments
hotnewtop
Profile icon
Coder100

Hello, that is because there is no default font with repl.it. I have experienced this with my code on canvas too, and I have created a solution.

  1. Import the registerFont
const { registerFont } = require('canvas');

Append this line and don't replace it with previous imports.

  1. Install a font.
    Go to like google fonts and then choose a font and install it. Then, unzip the folder and then drag the fonts in question to your repl.

  2. Register the font.

registerFont('path/to/font.ttf', { family: 'InsertFontNameHere' });
  1. Using the font
ctx.font = '30px InsertFontNameHere';

Hopes this helps! Be sure to accept it as the correct answer if it worked for you!

Profile icon
Trunks8257

@Coder100
Thanks! I will add it and see if it works

Profile icon
Coder100

no problem! @Trunks8257

Profile icon
Trunks8257

@Coder100
it worked, thank you!!!

Profile icon
Coder100

yay!!! no problem!!! What font did you use? @Trunks8257

Profile icon
Trunks8257

@Coder100
Semi Bold Open Sans

Profile icon
Coder100

nice! That's a good font! @Trunks8257

Profile icon
Trunks8257

@Coder100
yes, and I can use it thanks to you

Profile icon
OctagonalT

@Coder100 I'm still getting an error: Fontconfig error: Cannot load default config file

Profile icon
Coder100

Hmm send repl @OctagonalT

Profile icon
OctagonalT

@Coder100 Link?

Profile icon
Coder100
Profile icon
OctagonalT
Profile icon
Coder100
Profile icon
Coder100

Is the error fatal? @OctagonalT

Profile icon
OctagonalT

@Coder100 no, the program continues

Profile icon
Coder100

hmm, I am going to jump the conclusion that if that error only prints text, and your canvas works fine, you can safely ignore it @OctagonalT

Profile icon
OctagonalT

@Coder100 There's no text on the canvas image (dont judge the image pls)

Profile icon
Coder100
Profile icon
OctagonalT

@Coder100 It should have the text "hi" somewhere (its for testing) but there isn't

Profile icon
Coder100

hmm, can I make a quick repl and see if it works? @OctagonalT

Profile icon
OctagonalT
Profile icon
Coder100
Profile icon
OctagonalT

@Coder100 Can you tell me what needs to be changed for my repl?
(also sorry for not responding i had to go)

Profile icon
Coder100

your text is white lol @OctagonalT

Profile icon
OctagonalT

@Coder100 oh- shi-

Profile icon
Coder100

lol bad eyes go brr @OctagonalT
i definitely could see the text

Profile icon
OctagonalT

Thanks dude @Coder100

Profile icon
Coder100
Profile icon
marcos10pc

Thanks c:

Profile icon
TarunB1

@Coder100
i got the same issue could u explain wha file
t i have to add in my fonts

Profile icon
TarunB1

could u send ur rep
@Coder100

Profile icon
CrazyBotBoy

Nice! This is what I've been looking for.

Profile icon
Abdullah2222

thx Coder100

Profile icon
Abdullah2222

thank u so mush

Profile icon
FishyFlick

could u help me @Coder100
(node:340) UnhandledPromiseRejectionWarning: ReferenceError: registerFont is not defined

Profile icon
Coder100

hello, i think it has been fixed on discord? @FishyFlick

Profile icon
FishyFlick

ye ty <3 @Coder100

Profile icon
JabalanProducti

@Coder100 i got same problem to -_-

Profile icon
JabalanProducti

can you help me? @Coder100