Optional and peer dependencies
sultan99 opened this issue · 7 comments
I'm making a library that have optional and peer dependencies.
The end-users (developers) of my library may optionally install package styled-components
or not.
But dynamic-cdn-webpack
plugin always injects the optional package in the index.html, even it was not installed!
My library package.json
has section optionalDependencies
, so there is a way how to know which is optional and peer dependency.
Here is a project to produce the bug:
git clone git@github.com:sultan99/rol-vs-jsx.git
cd rol-vs-jsx
npm i
npm run build
After build check folder dist/rol
. If you open index.html you will find it includes script with styled-components
which should not be because the package is not used in the project.
Can you fix the bug?
Hey @sultan99,
So, I believe the library's current implementation of dealing with peer dependencies is what works well for most libraries. A peer dependency isn't optional and it shouldn't be treated as such.
If you were to remove styled-components
from peerDependencies
, I think the output would be as you expect it to be.
Hi @aulisius!
When I remove the styled-components from peerDependencies, then it breaks when I install the styled-components in the parent project:
You can check this version https://unpkg.com/react-on-lambda@0.3.9/dist/react-on-lambda.min.js built without the package in peerDependencies:
This project uses styled-component if install react-on-lambda v0.3.9 then it stops to work.
@sultan99, I was able to run the above mentioned project successfully with react-on-lambda@0.3.9
.
$ npm ls styled-components
rol-usage@0.1.0 /Developer/rol-usage
├─┬ react-on-lambda@0.3.9
│ └── styled-components@4.2.0 deduped
└── styled-components@4.2.0