Closed wmcmurray closed 2 years ago
Thank you for your suggestion.
But it seems that your sample is for optionalDependencies
but not for peerDependencies
, and optionalDependencies
means the library could be optional, and the project can work without it, but peerDependencies
means that is a required option. You will receive a warning if the peerDependency is not installed when running npm install
or yarn
.
I think placing require
in the top level of a module can make it easier to identify dependencies, so usually I won’t put it in statements unless really necessary.
Here are some links for reference:
https://nodejs.org/en/blog/npm/peer-dependencies/
https://eslint.org/docs/rules/global-require
I tried to use this plugin in a project that does not use
html-webpack-plugin
at all, and I get this error in webpack becausehtml-webpack-plugin
is required, and since it's not listed in the dependencies, it does not get installed by npm.Here is where it is required and used :
https://github.com/terence55/themes-switch/blob/f595ce091e0eb54508028782797f66623f3c39b9/src/ThemesGeneratorPlugin.js#L6
https://github.com/terence55/themes-switch/blob/f595ce091e0eb54508028782797f66623f3c39b9/src/ThemesGeneratorPlugin.js#L127
I saw it being listed in the peerDependencies, so I poked around the npm documentation and found this code exemple that might show a better way of handling such dependency :
Thank you !