Encountered an issue where I needed the same package to be included as both a dependency
and a devDependency
.
The specific packages in question are @babel/core
and @babel/preset-env
.
Reason?
Because my package is designed to facilitate transpilation of another part of the project in the future:
- Original source code is transpiled using babel (as a dev dependency).
- Transpiled code is then published on NPM.
- Later, the transpiled source from NPM will be processed through webpack (which relies on
babel-loader
and therefore requires@babel/core
). This step will be performed by end users usingwebpack
.
I aim to include all necessary dev-assets (excluding webpack) within the package so that end users do not need to separately install babel-loader
, @babel/core
, etc.
Initially, I considered adding them as dependencies, but found this approach somewhat messy.
This could potentially be categorized as an X/Y
problem?
The solution that seems to work involves:
- Creating a separate package named
xxx-dev-dependencies
. - Incorporating the dependencies required for webpack transpilation into that subsequent package.
- Requiring the package and passing the modules to webpack.
HOWEVER ... I consistently receive a warning when installing the dev dependency package:
[email protected] necessitates a peer version of webpack@>=2 which is currently missing. It is necessary to manually install peer dependencies.
Even though I have added webpack to peerDependencies
as illustrated below:
"name": "xxx-dev-dependencies",
"dependencies": {
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"babel-loader": "^8.1.0"
},
"peerDependencies": {
"webpack": "4.x"
}