question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Third level peerDependency is not excluded / canvas.node: invalid ELF header

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mzl-mdcommented, May 17, 2022

flatDep() is not called as far as I can tell.

I can’t think of a good way to implement the exclude for third level dependencies, since the plugin-internal npm install will always install them and deleting or not including them in the bundle would still keep all fourth level dependencies of the excluded dependencies.

But as I now understand, our problem is caused by the plugin-internal npm install installing the optional peerDependencies of our dependencies. So in our case, the best solution would be to use

    installExtraArgs:
      - '--legacy-peer-deps'

TL;DR: Our problem can be solved with a different solution, but the bug is still valid in my opinion.

0reactions
samchungycommented, May 17, 2022

Oh I see because you are not using package individually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Losing my mind with this build error. Please help! - Node.js SDK
When it gets to the business of running the node server js file, I get the following: ... invalid ELF header] ...
Read more >
floydspace/serverless-esbuild (Raised $0.00) - Issuehunt
Third level peerDependency is not excluded / canvas.node: invalid ELF header. Unfunded#312created bymzl-md. $0.00. Third level peerDependency is not ...
Read more >
node.js - npm install fails with Conflicting peer dependency
For first error I tried to install npm by below 2 command in Terminal one after another. It fixes for me: npm install...
Read more >
npm add user - OSCHINA - 中文开源技术交流社区
typescript-npm-package-template Template to kickstart creating a Node.js ... and that there are no unpulled changes Reinstalls dependencies to ensure your ...
Read more >
https://huggingface.co/dbernsohn/roberta-javascrip...
diff --git a/vocab.json b/vocab.json new file mode 100644--- /dev/null +++ b/vocab.json @@ -0,0 +1 @@ +{"<s>":0,"<pad>":1,"</s>":2,"<unk>":3,"<mask>":4,"!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found