You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Everything under apps (e.g. - app-1 and app-2) has its own package.json.
If I put the above dependencies in each app-1 and app-2, everything works as expected, but that is exactly what I'm trying to avoid copy/pasting.
The Problem
I want both app-1 and app-2 to inherit ALL of the apps workspace dependencies ANDdevDependencies sections as a base (from which it can extend). These are base dependencies needed to create a working application, and I want to enforce a baseline of consistency. Eventually I'd like to also extend this idea to an apis workspace and others.
What I've Tried
Adding Workspace Dependencies via CLI
To dependencies
yarn workspace app-1 add apps
Result:
"dependencies": {
"apps": "workspace:apps"
}
To devDependencies
yarn workspace app-1 add --dev apps
Error if entry exists from above step:
Usage Error: Package "apps" is already listed as a regular dependency - remove the -D,-P flags or remove it from your dependencies first
Otherwise
"devDependencies": {
"apps": "workspace:apps"
}
To peerDependencies
yarn workspace app-1 add --peer apps
Result:
"peerDependencies": {
"apps": "workspace:apps"
}
After trying the above CLI options in a variety of different ways for app-1 and then running yarn and yarn workspace app-1 run start (a script that initiates webpack dev server), the most common outcome is that webpack cannot be found.
Once I explicitly install webpack on app-1 and restart, it will continue to cascade with the missing dependencies as you would expect if this was not a monorepo.
I also played around with copying/pasting all the dependencies, and setting their versions to "*" in a variety of ways (peer, dev, and lumping the dependencies differently in the parent apps workspace).
None of these attempts really yielded satisfactory outcome that got me closer to solving the original problem, which is to create a common baseline of devDependencies and dependencies for every workspace under apps -- without needing to explicitly re-type every single dependency in every single workspace.
Is there another way to go about this that I'm missing?
I've effectively managed to parameterize the webpack config into the parent apps workspace as well as extending the TypeScript config by using the "extends" field in the children workspaces' tsconfig.json.
If I could stop re-defining and repeating all these front-end related dependencies, this would go a really long way to creating an amazing project stack.
I realize this seems kind of weird because apps itself isn't really a "project", but an intermediate workspace to house this baseline of dependencies.
I have not come across any other approaches to solving this particular problem, so I'm open to other ways of accomplishing this (ideally in the most declarative way possible).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The Setup
I have a multi-nested monorepo with a top level
package.json
:And
apps
, itself, is a nested workspace within this:Everything under
apps
(e.g. -app-1
andapp-2
) has its ownpackage.json
.If I put the above dependencies in each
app-1
andapp-2
, everything works as expected, but that is exactly what I'm trying to avoid copy/pasting.The Problem
I want both
app-1
andapp-2
to inherit ALL of theapps
workspace dependencies ANDdevDependencies
sections as a base (from which it can extend). These are base dependencies needed to create a working application, and I want to enforce a baseline of consistency. Eventually I'd like to also extend this idea to anapis
workspace and others.What I've Tried
Adding Workspace Dependencies via CLI
To
dependencies
yarn workspace app-1 add apps
Result:
To
devDependencies
yarn workspace app-1 add --dev apps
Error if entry exists from above step:
Otherwise
To
peerDependencies
yarn workspace app-1 add --peer apps
Result:
After trying the above CLI options in a variety of different ways for
app-1
and then runningyarn
andyarn workspace app-1 run start
(a script that initiates webpack dev server), the most common outcome is thatwebpack
cannot be found.Once I explicitly install
webpack
onapp-1
and restart, it will continue to cascade with the missing dependencies as you would expect if this was not a monorepo.I also played around with copying/pasting all the dependencies, and setting their versions to
"*"
in a variety of ways (peer, dev, and lumping the dependencies differently in the parentapps
workspace).None of these attempts really yielded satisfactory outcome that got me closer to solving the original problem, which is to create a common baseline of
devDependencies
anddependencies
for every workspace underapps
-- without needing to explicitly re-type every single dependency in every single workspace.Is there another way to go about this that I'm missing?
I've effectively managed to parameterize the webpack config into the parent
apps
workspace as well as extending the TypeScript config by using the"extends"
field in the children workspaces'tsconfig.json
.If I could stop re-defining and repeating all these front-end related dependencies, this would go a really long way to creating an amazing project stack.
I realize this seems kind of weird because
apps
itself isn't really a "project", but an intermediate workspace to house this baseline of dependencies.I have not come across any other approaches to solving this particular problem, so I'm open to other ways of accomplishing this (ideally in the most declarative way possible).
Beta Was this translation helpful? Give feedback.
All reactions