Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Lambda - canvas.node: invalid ELF header #135

Open
AleksandarGT opened this issue Jul 31, 2023 · 2 comments
Open

AWS Lambda - canvas.node: invalid ELF header #135

AleksandarGT opened this issue Jul 31, 2023 · 2 comments

Comments

@AleksandarGT
Copy link

Hello, I have been trying to use ChartJsNodeCanvas with AWS Lambda + AWS Amplify, but I keep having problems with node-canvas with the error 'var/task/node_modules/canvas/build/Release/canvas.node: invalid ELF header'.

So far what I have tried is to use an AWS Lambda Layer for node-canvas:
Lambda layer

Now when I import canvas it doesn't throw error and successfully console logs it

const canvas = require('canvas')
console.log(canvas)

However the moment I import chartjs-node-canvas it throws invalid ELF header.

{
    "errorType": "Error",
    "errorMessage": "/var/task/node_modules/canvas/build/Release/canvas.node: invalid ELF header",
    "code": "ERR_DLOPEN_FAILED",
    "stack": [
        "Error: /var/task/node_modules/canvas/build/Release/canvas.node: invalid ELF header",
        "    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1282:18)",
        "    at Module.load (node:internal/modules/cjs/loader:1076:32)",
        "    at Function.Module._load (node:internal/modules/cjs/loader:911:12)",
        "    at Module.require (node:internal/modules/cjs/loader:1100:19)",
        "    at require (node:internal/modules/cjs/helpers:108:18)",
        "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)",
        "    at Module._compile (node:internal/modules/cjs/loader:1198:14)",
        "    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)",
        "    at Module.load (node:internal/modules/cjs/loader:1076:32)",
        "    at Function.Module._load (node:internal/modules/cjs/loader:911:12)"
    ]
}

I am confused, because the lambda layer provides node canvas version @2.11.2 which should be compatible with chartjs node canvas.

    "chart.js": "^3.9.1",
    "chartjs-node-canvas": "^4.1.6"

I can provide more information if this wasn't enough.

@baxol
Copy link

baxol commented Dec 4, 2023

Any solution?

@AleksandarGT
Copy link
Author

Remove chart.js as a dependancy in package.json and rely entirely on the lambda layer provided.
https://github.com/charoitel/lambda-layer-canvas-nodejs/issues/19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants