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

Comments

Projects
None yet
2 participants
@guillaumervls
Copy link

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

This comment has been minimized.

Copy link
Member

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 referenced this issue Sep 19, 2017

Merged

Add and include peer dependencies #231

6 of 7 tasks complete
@HyperBrain

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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