Describe the bug
We have a lambda with dependency jsdom, which has peerDependency canvas. Until recently, canvas was not installed by npm and not bundled by esbuild. If canvas is present, an error canvas.node: invalid ELF header is thrown at runtime.
Since the latest update, our devDependency pdf-visual-diff requires canvas. This leads to canvas beeing included in the bundle and runtime errors.
We were hoping to prevent canvas from beeing included by adding it to exclude in the serverless.yml, but that does not work.
To Reproduce
Dependencies in package.json:
"dependencies": {
"jsdom": "19.0.0"
},
"devDependencies": {
"pdf-visual-diff": "0.6.0",
"serverless": "3.17.0",
"serverless-esbuild": "1.27.1"
}
Config in serverless.yml:
custom:
esbuild:
exclude:
- "aws-sdk"
- "canvas"
external:
- jsdom
Run npx sls package and unzip the bundle => node_modules/canvas exists :(
Expected behavior
node_modules/canvas is not included in the bundle.
Versions (please complete the following information):
- OS: Mac
- Serverless Framework Version: 3.17.0
- Plugin Version: 1.27.1
Workaround
Deleting the canvas directory works, but all dependencies of canvas stay included in the bundle:
custom:
esbuild:
packagerOptions:
scripts:
- rm -rf node_modules/canvas
Describe the bug
We have a lambda with dependency jsdom, which has peerDependency canvas. Until recently, canvas was not installed by npm and not bundled by esbuild. If canvas is present, an error
canvas.node: invalid ELF headeris thrown at runtime.Since the latest update, our devDependency
pdf-visual-diffrequirescanvas. This leads tocanvasbeeing included in the bundle and runtime errors.We were hoping to prevent
canvasfrom beeing included by adding it toexcludein the serverless.yml, but that does not work.To Reproduce
npm inpm testDependencies in package.json:
Config in serverless.yml:
Run
npx sls packageand unzip the bundle =>node_modules/canvasexists :(Expected behavior
node_modules/canvasis not included in the bundle.Versions (please complete the following information):
Workaround
Deleting the canvas directory works, but all dependencies of canvas stay included in the bundle: