Fontconfig Error on Railway Deployment

Hello, I am currently working on a Node.js project that uses chartjs-node-canvas ^4.1.6 and chartjs-plugin-annotation ^2.2.1. The project is deployed on Railway. During the deployment to production, I encountered an error while trying to generate a chart. All letters on the chart were replaced by squares, and the console logged an error: Fontconfig error: Cannot load default config file. From my understanding, this error is related to the font configuration in the environment. The Fontconfig library, which is used by Chart.js to render text, seems to be unable to find its configuration file. This suggests that the environment where my application is running does not have Fontconfig installed or properly configured. My project is hosted on Railway, which runs on Nixpacks (which in turn runs on Docker). However, I don't have direct control over the Dockerfile or the system's package manager. I only have access to the shell.nix and railway.json files. To try and resolve the issue, I added fontconfig to the nixPkgs array in the setup phase of my railway.json file, as shown below:
{
"builds": {
"my-app": {
"phases": {
"setup": {
"packages": [
"fontconfig"
]
}
}
}
}
}
{
"builds": {
"my-app": {
"phases": {
"setup": {
"packages": [
"fontconfig"
]
}
}
}
}
}
Despite this, the error persists. I'm unsure if the fontconfig package is being installed correctly or if the configuration is not being loaded as expected. I would greatly appreciate any assistance or suggestions on how to resolve this issue. If there are any additional details that would be helpful, please let me know. Thank you in advance for your help.
Project id: a04e5aab-0452-4be2-b078-3e2d1e5a1503
Platform: Node.js v18.12.1
Used technologies: Nest.js / NPM
Repo: https://github.com/dudematthew/pla-manager/tree/production
Project id: a04e5aab-0452-4be2-b078-3e2d1e5a1503
Platform: Node.js v18.12.1
Used technologies: Nest.js / NPM
Repo: https://github.com/dudematthew/pla-manager/tree/production
Solution:
Solved Dockerfile worked. Here's its code: ```dockerfile Use an official Node.js 16 runtime as the base image...
Jump to solution
12 Replies
Percy
Percy16mo ago
Project ID: a04e5aab-0452-4be2-b078-3e2d1e5a1503
MantisInABox
MantisInABox16mo ago
You can always create a dockerfile that installs the required libraries and launches your app. The build system will use your dockerfile to deploy
HipsterSavage
HipsterSavageOP16mo ago
Will Railway options be ignored then? Also what about default Railway procedures, will my Dockerfile replace them?
MantisInABox
MantisInABox16mo ago
It will deploy your dockerfile however it is written
HipsterSavage
HipsterSavageOP16mo ago
I understand for now. Will try my luck with the Dockerfile then, thank You! Here's my Dockerfile placed in the main folder of the app. Is it configured properly for Railway standards?
# Use an official Node.js 16 runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Install fontconfig
RUN apt-get update && apt-get install -y fontconfig

# Copy the current directory contents into the container at /app
COPY . .

# Make port 80 available to the world outside this container
EXPOSE 80

# Run the build command
RUN npm run deploy

# Specify the start command
CMD [ "npm", "run", "start:prod" ]
# Use an official Node.js 16 runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Install fontconfig
RUN apt-get update && apt-get install -y fontconfig

# Copy the current directory contents into the container at /app
COPY . .

# Make port 80 available to the world outside this container
EXPOSE 80

# Run the build command
RUN npm run deploy

# Specify the start command
CMD [ "npm", "run", "start:prod" ]
MantisInABox
MantisInABox16mo ago
As long as it runs on your system, it will run on Railway. You will just need to create an environment variable on your service called PORT and set it to 80 since you are specifying a port
HipsterSavage
HipsterSavageOP16mo ago
Could I just remove the port line?
MantisInABox
MantisInABox16mo ago
You can, but then you would need to make sure your code references the $PORT environment variable so it will pick up the port assigned by railway
HipsterSavage
HipsterSavageOP16mo ago
of course, thank You
Solution
HipsterSavage
HipsterSavage16mo ago
Solved Dockerfile worked. Here's its code:
# Use an official Node.js 16 runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Install fontconfig
RUN apt-get update && apt-get install -y fontconfig

# Copy the current directory contents into the container at /app
COPY . .

# Make port 80 available to the world outside this container
# Note: it may be not needed for your specific setup
EXPOSE 80

# Run the build command
RUN npm run deploy

# Specify the start command
CMD [ "npm", "run", "start:prod" ]
# Use an official Node.js 16 runtime as the base image
FROM node:16

# Set the working directory in the container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Install fontconfig
RUN apt-get update && apt-get install -y fontconfig

# Copy the current directory contents into the container at /app
COPY . .

# Make port 80 available to the world outside this container
# Note: it may be not needed for your specific setup
EXPOSE 80

# Run the build command
RUN npm run deploy

# Specify the start command
CMD [ "npm", "run", "start:prod" ]
HipsterSavage
HipsterSavageOP16mo ago
Thank You @Vin
MantisInABox
MantisInABox16mo ago
No problem
Want results from more Discord servers?
Add your server