mastilver/dynamic-cdn-webpack-plugin

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.

image

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:
image

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:
image

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

Screen Shot 2019-04-08 at 6 13 28 AM

I don't know why I get the error 🤔...

My environment:

  • win10
  • npm 6.9.0 (tried on 6.8.0 same issue)
  • node v11.10.0

image

I have checked it on another PC, worked!
Looks I have some issue with that computer.

Anyway, @aulisius thank you for helping and I close this issue.

@sultan99, maybe you can try removing the package-lock.json file and see if it helps.