Automattic / Automattic/node-canvas
AWS Lambda: cannot find canvas.node
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 1.2k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 1
Description
### Issue
Attempting to use Canvas on Lambda results in the following error:
```
/var/task/node_modules/canvas/build/Release/canvas.node:
cannot open shared object file: No such file or directory
```
### Context
I'm attempting to use `chartjs-node-canvas` on Lambda.
The [Installation Guide](https://github.com/Automattic/node-canvas/wiki/Installation:-AWS-Lambda) says that Canvas 2 should work, so long as it is installed on a Linux docker container, so I have used the following Dockerfile
```
FROM amazonlinux:2
RUN yum update -y && yum group install "Development Tools" -y
RUN curl -fsSL https://rpm.nodesource.com/setup_14.x | bash - && yum install -y nodejs
RUN yum install cairo-devel libjpeg-turbo-devel giflib-devel pango-devel -y
```
to set up a container, and then run `npm install` inside the container, before packaging up the `node_modules` and `output` folders into one `.zip` file.
Unzipping the file locally shows that `canvas.node` exists at `/node_modules/canvas/build/Release/canvas.node`, but the error mentioned above occurs when running the lambda.
### Things I've tried that (sadly) haven't worked (yet)
- Moving the location of `node_modules` folder relative to the `index.js` file — this made zero difference as Lambda no longer seems to care where the folder is, so long as there's a name match
- `chmod +x ./node_modules/canvas/build/Release/canvas.node`
### Steps to Reproduce
Run the following as part of a Lambda function
```js
const canvas = new ChartJSNodeCanvas({ width: 3840, height: 2160 });
const image = canvas.renderToBufferSync(data);
```
### Your Environment
* `npm list canvas`
```sh
`-- chartjs-node-canvas@4.1.4
`-- canvas@2.8.0
```
* Environment
node v14.18.1 on AmazonLinux2 Docker container
node v14.18.1 on macOS 11.5.2
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.