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

2nd level peerDependencies not packed when not used directly in the project #223

Closed
guillaumervls opened this issue Sep 13, 2017 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@guillaumervls
Copy link

@guillaumervls guillaumervls commented Sep 13, 2017

Hi,

As I understand, dependencies are packed if :

  • they are listed under dependencies in package.json

AND

  • they are part of Webpack compilation "chunks" (i.e. are imported in user's code)

What's the use of the second condition ? A dependency can be in package.json and not directly used in code : in the case of a peer-dependency of other dependencies... However if not packed these dependencies will crash...

Cheers !

PS : The solution I use for this is to import the peer-dependency in my handler.js without actually doing anything with it.

@HyperBrain
Copy link
Member

@HyperBrain HyperBrain commented Sep 13, 2017

Hi @guillaumervls ,
that's indeed a valid edge case 👍 , as for a peer dependency your code does not reference it but the dependency that introduces it does. This should be fixed by analyzing the dependency tree for peer dependencies of 2nd level dependencies that must be included.

To your question: A major use case for the plugin is to let Webpack optimize the code and only bundle external modules that are actually used. This leads to much smaller packages and faster Lambda cold start times. As soon as the peer dependency bug is fixed it should be consistent again.
As a function deployment is not a library but final code, it is also valid to use node-externals whitelist parameter to bundle a complete dependency into the code and let Webpack dismiss not needed 2nd level dependencies (optimally used together with the ES6 compatible UglifyJSPlugin of Webpack 3.x).

For dependencies that are neither peers nor referenced directly, there's a feature request #217 for the next release that will allow to explicitly add a dependency.

@HyperBrain HyperBrain added the bug label Sep 13, 2017
@HyperBrain HyperBrain changed the title Dependencies not packed 2nd level peerDependencies not packed when not used directly in the project Sep 13, 2017
@HyperBrain HyperBrain self-assigned this Sep 19, 2017
@HyperBrain HyperBrain added this to the 3.1.0 milestone Sep 19, 2017
@HyperBrain HyperBrain mentioned this issue Sep 19, 2017
6 of 7 tasks complete
@HyperBrain
Copy link
Member

@HyperBrain HyperBrain commented Sep 19, 2017

@guillaumervls Can you check with the version from #231 if that solves the problem (i.e. you do not need to reference the unused peer dependency)?

@HyperBrain
Copy link
Member

@HyperBrain HyperBrain commented Sep 22, 2017

Released with 3.1.0

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

Successfully merging a pull request may close this issue.

None yet
2 participants