charoitel / lambda-layer-canvas-nodejs

Cairo backed Mozilla Web Canvas API implementation layer for AWS Lambda
https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:990551184979:applications~lambda-layer-canvas-nodejs
MIT License
91 stars 25 forks source link

Error: when using the layer in Node v18 #13

Closed stuharben closed 1 year ago

stuharben commented 1 year ago

Hi @charoitel - thank you for this work. Really helped me out.

We built the layer using your AWS serverless application. It works fine in v16, though when using as a layer in Node v18 we get intermittent errors:

    "errorType": "Error",
    "errorMessage": "The module '/opt/nodejs/node_modules/canvas/build/Release/canvas.node'\nwas compiled against a different Node.js version using\nNODE_MODULE_VERSION 93. This version of Node.js requires\nNODE_MODULE_VERSION 108. Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).",
    "code": "ERR_DLOPEN_FAILED",

We also used Cloud9 to step through your code and run it just for Node v18 and it gives a similar error:

 "errorType": "Error",
  "errorMessage": "The module '/opt/nodejs/node_modules/canvas/build/Release/canvas.node'\nwas compiled against a different Node.js version using\nNODE_MODULE_VERSION 93. This version of Node.js requires\nNODE_MODULE_VERSION 108. Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).",
  "trace": [
    "Error: The module '/opt/nodejs/node_modules/canvas/build/Release/canvas.node'",
    "was compiled against a different Node.js version using",
    "NODE_MODULE_VERSION 93. This version of Node.js requires",
    "NODE_MODULE_VERSION 108. Please try re-compiling or re-installing",
    "the module (for instance, using `npm rebuild` or `npm install`).",

Thank you so much in advance!

DavidVaness commented 1 year ago

I have the same error

DavidVaness commented 1 year ago

This was a mistake on my end, I can't replicate this error

charoitel commented 1 year ago

@DavidVaness I found the build script should move the node_modules folder to either node16 or node18 and ensure there should be no /opt/nodejs/node_modules folder, still have to fix it. May I know if you could run your Lambda function or not at the moment?

DavidVaness commented 1 year ago

I am sorry, I have this error on node18, must have been some caching issue that lead me to assume the 18 works while receiving data from the working v16

And the error message supports your path to fix the issue, as he is unable to link the files

{     "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 Module._extensions..node (node:internal/modules/cjs/loader:1243:18)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/canvas.js:9:18)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/index.js:1:16)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at node_modules/konva/cmj/index-node.js (/node_modules/konva/cmj/index-node.js:4:16)",         "    at __require (/var/task/src/functions/render/handler.js:9:51)",         "    at Object.<anonymous> (/src/libs/canvas-creatives/entities/socialmedia/socialmedia.entity.ts:1:19)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at _tryRequireFile (file:///var/runtime/index.mjs:915:37)",         "    at _tryRequire (file:///var/runtime/index.mjs:965:25)",         "    at _loadUserApp (file:///var/runtime/index.mjs:994:22)",         "    at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:27)",         "    at start (file:///var/runtime/index.mjs:1200:42)",         "    at file:///var/runtime/index.mjs:1206:7",         "    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)",         "    at async Promise.all (index 0)",         "    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)",         "    at async loadESM (node:internal/process/esm_loader:91:5)",         "    at async handleMainPromise (node:internal/modules/run_main:65:12)"     ] } | 2023-01-16T14:57:22.300Z undefined ERROR Uncaught Exception {"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 Module._extensions..node (node:internal/modules/cjs/loader:1243:18)"," at Module.load (node:internal/modules/cjs/loader:1037:32)"," at Module._load (node:internal/modules/cjs/loader:878:12)"," at Module.require (node:internal/modules/cjs/loader:1061:19)"," at require (node:internal/modules/cjs/helpers:103:18)"," at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)"," at Module._compile (node:internal/modules/cjs/loader:1159:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)"," at Module.load (node:internal/modules/cjs/loader:1037:32)"," at Module._load (node:internal/modules/cjs/loader:878:12)"," at Module.require (node:internal/modules/cjs/loader:1061:19)"," at require (node:internal/modules/cjs/helpers:103:18)"," at Object.<anonymous> (/var/task/node_modules/canvas/lib/canvas.js:9:18)"," at Module._compile (node:internal/modules/cjs/loader:1159:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)"," at Module.load (node:internal/modules/cjs/loader:1037:32)"," at Module._load (node:internal/modules/cjs/loader:878:12)"," at Module.require (node:internal/modules/cjs/loader:1061:19)"," at require (node:internal/modules/cjs/helpers:103:18)"," at Object.<anonymous> (/var/task/node_modules/canvas/index.js:1:16)"," at Module._compile (node:internal/modules/cjs/loader:1159:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)"," at Module.load (node:internal/modules/cjs/loader:1037:32)"," at Module._load (node:internal/modules/cjs/loader:878:12)"," at Module.require (node:internal/modules/cjs/loader:1061:19)"," at require (node:internal/modules/cjs/helpers:103:18)"," at node_modules/konva/cmj/index-node.js (/node_modules/konva/cmj/index-node.js:4:16)"," at __require (/var/task/src/functions/render/handler.js:9:51)"," at Object.<anonymous> (/src/libs/canvas-creatives/entities/socialmedia/socialmedia.entity.ts:1:19)"," at Module._compile (node:internal/modules/cjs/loader:1159:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)"," at Module.load (node:internal/modules/cjs/loader:1037:32)"," at Module._load (node:internal/modules/cjs/loader:878:12)"," at Module.require (node:internal/modules/cjs/loader:1061:19)"," at require (node:internal/modules/cjs/helpers:103:18)"," at _tryRequireFile (file:///var/runtime/index.mjs:915:37)"," at _tryRequire (file:///var/runtime/index.mjs:965:25)"," at _loadUserApp (file:///var/runtime/index.mjs:994:22)"," at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:27)"," at start (file:///var/runtime/index.mjs:1200:42)"," at file:///var/runtime/index.mjs:1206:7"," at ModuleJob.run (node:internal/modules/esm/module_job:193:25)"," at async Promise.all (index 0)"," at async ESMLoader.import (node:internal/modules/esm/loader:530:24)"," at async loadESM (node:internal/process/esm_loader:91:5)"," at async handleMainPromise (node:internal/modules/run_main:65:12)"]}
-- | --
  | 2023-01-16T15:57:22.895+01:00Copy2023-01-16T14:57:22.895Z   undefined   ERROR   Uncaught Exception  {     "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 Module._extensions..node (node:internal/modules/cjs/loader:1243:18)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/bindings.js:3:18)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/lib/canvas.js:9:18)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at Object.<anonymous> (/var/task/node_modules/canvas/index.js:1:16)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at node_modules/konva/cmj/index-node.js (/node_modules/konva/cmj/index-node.js:4:16)",         "    at __require (/var/task/src/functions/render/handler.js:9:51)",         "    at Object.<anonymous> (/src/libs/canvas-creatives/entities/socialmedia/socialmedia.entity.ts:1:19)",         "    at Module._compile (node:internal/modules/cjs/loader:1159:14)",         "    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)",         "    at Module.load (node:internal/modules/cjs/loader:1037:32)",         "    at Module._load (node:internal/modules/cjs/loader:878:12)",         "    at Module.require (node:internal/modules/cjs/loader:1061:19)",         "    at require (node:internal/modules/cjs/helpers:103:18)",         "    at _tryRequireFile (file:///var/runtime/index.mjs:915:37)",         "    at _tryRequire (file:///var/runtime/index.mjs:965:25)",         "    at _loadUserApp (file:///var/runtime/index.mjs:994:22)",         "    at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:27)",         "    at start (file:///var/runtime/index.mjs:1200:42)",         "    at file:///var/runtime/index.mjs:1206:7",         "    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)",         "    at async Promise.all (index 0)",         "    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)",         "    at async loadESM (node:internal/process/esm_loader:91:5)",         "    at async handleMainPromise (node:internal/modules/run_main:65:12)"     ] }

<br class="Apple-interchange-newline">
charoitel commented 1 year ago

@DavidVaness, @stuharben,

The maintenance release v2.11.1 of the canvas layer has just been updated on serverless repo, could you please try the latest release? You may deploy the latest layer through the serverless repo or upload the latest release from the Releases section. Please let me know if the release works stable at your side or not. Thank you.