node-canvas-lambda icon indicating copy to clipboard operation
node-canvas-lambda copied to clipboard

e.CanvasRenderingContext2dInit is not a function

Open carlesandres opened this issue 4 years ago • 2 comments

I am getting this error after following the steps in this repo.

e.CanvasRenderingContext2dInit is not a function

The way I construct my lambda is by bundling with Parcel from the function's entry point, letting it figure out what to bundle, then zipping it and uploading. My bundle is definitely including a copy of canvas from my local node_modules folder and is very likely the cause of this error. That said, I am new to lambdas and I find it difficult to infer from the readme how people workaround the issue of excluding the local 'canvas' module from the zip they upload to AWS. If I managed to finally exclude my local copy of canvas from the zip it, is there a change that const Canvas = require('canvas') won't pick the canvas module from the layer?

carlesandres avatar Jan 29 '20 20:01 carlesandres

@carlesandres It may be loading canvas from your node_modules directory. Make sure you're not deploying canvas with your function, you don't need it since it's already in the layer. Maybe just put it as a devDependancy.

jwerre avatar Feb 10 '20 19:02 jwerre

Thanks. I’m sure is that. I’ve taken a detour from my original approach for now by using OffscreenCanvas combined with service workers to generate hi-res images on the client, but I will go back to this soon. I’ll let you know how it goes.

On Mon, 10 Feb 2020 at 19:30, Jonah Werre [email protected] wrote:

@carlesandres https://github.com/carlesandres It may be loading canvas from your node_modules directory. Make sure you're not deploying canvas with your function, you don't need it since it's already in the layer. Maybe just put it as a devDependancy.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jwerre/node-canvas-lambda/issues/7?email_source=notifications&email_token=AABRTVKK7FWG3KHH4ZRCWVDRCGTMBA5CNFSM4KNLJCQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELJ5S3A#issuecomment-584309100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABRTVPWXUDL6BTF3HAUQXDRCGTMBANCNFSM4KNLJCQA .

carlesandres avatar Feb 10 '20 19:02 carlesandres