Automattic / Automattic/node-canvas

Running under AWS Lambda (docker, Node 18): undefined symbol: pango_context_set_round_glyph_positions

Open
#2,250 5 comments 8 reactions 0 assignees View on GitHub
Installation help
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue or Feature
- [x] If this is an issue with installation, I have read the [troubleshooting guide](https://github.com/Automattic/node-canvas/issues/1511).

When deploying to AWS lambda using a Docker image we encounter the following error:
> ```/var/lang/bin/node: symbol lookup error: /var/task/node_modules/canvas/build/Release/canvas.node: undefined symbol: pango_context_set_round_glyph_positions```

I believe this is related to the changes [made here](https://github.com/Automattic/node-canvas/pull/2184/commits/f783d74d772a51031f2ed9317c25c7a8339e311b#diff-b602e59ab0b4746360680c1ac08e080841956f3832dd2e94d99fb90922b6504aR177). It worked in version 2.11.0 without issue.

In the base image I am building from (https://gallery.ecr.aws/lambda/nodejs) we can see the version of `pango` is < 1.44.0, but for some reason the following condition evaluates to true when canvas is compiled:

From canvas `src/CanvasRenderingContext2d.cc`:
```cc
#if PANGO_VERSION_CHECK(1, 44, 0)
pango_context_set_round_glyph_positions(pango_layout_get_context(_layout), FALSE);
#endif
```

Version on the AWS Lambda image:
```
bash-4.2# pango-view --version
pango-view (pango) 1.42.3
```

So I am a bit confused as to why the `pango_context_set_round_glyph_positions` call is being compiled in the `canvas` target.

--

## Steps to Reproduce

Example Dockerfile:
```
FROM --platform=linux/amd64 public.ecr.aws/lambda/nodejs:18

RUN yum -y update \
&& yum -y groupinstall "Development Tools" \
&& yum install -y nodejs gcc-c++ cairo-devel \
libjpeg-turbo-devel pango-devel giflib-devel \
zlib-devel librsvg2-devel

COPY package.json ${LAMBDA_TASK_ROOT}
COPY yarn.lock ${LAMBDA_TASK_ROOT}

RUN npm install -g yarn
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install

COPY dist ${LAMBDA_TASK_ROOT}/dist

RUN yum remove -y cairo-devel libjpeg-turbo-devel \
pango-devel giflib-devel zlib-devel librsvg2-devel

ENV LD_PRELOAD=/var/task/node_modules/canvas/build/Release/libz.so.1

CMD [ "dist/example.execute" ]
```

`dist/example.js`:
```js
import canvas from 'canvas';

export const execute = async (event, context) => {
var ctx = canvas.createCanvas(200, 200).getContext('2d');
};
```

## Your Environment
* Version of node-canvas: `2.11.2`
* Environment: Docker (`linux/amd64`), AWS Lambda (although reproduces locally), Node 18

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.