question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Case Study] How to select node modules for an individual app deployment within a multi-app monorepo?

See original GitHub issue

Hi, firstly thanks for the great work at Yarn.

As I understand, authors of Yarn V2 has mentioned a lot of times that you have no intentions to support nohoist in V2.

I wonder if there is an alternative way to support multi-app monorepo deployment, especially on node module management?

Say, a monorepo structure like 👇

  • package.json

  • apps

    • web-service-a
      • package.json
      • Dockerfile
    • search-service-b
      • package.json
      • Dockerfile
    • admin-service-c
      • package.json
      • Dockerfile
  • shared-modules

    • lib-a
      • package.json
    • lib-b
      • package.json

As a typical multi-app monorepo pattern, each of the apps is an individual deployable HTTP server. Monorepo benefits us for cross-API type checking, lib sharing, deployment order management, etc. Having this, an essential requirement is to deploy one app like web-service-a with only its required node modules.

Previously, we were able to use Yarn V1 "nohoist": ["**"] to achieve node module separation during Docker image build-time.

Describe the goal of the investigation

Investigate if Yarn V2 suits multi-app monorepos.

Investigation report

Ideally, we would want Yarn V2 to be able to separate or assist us to separate node modules for individual packages. We don’t mind using hoisting as it is at development-time. But for production deployment, we will need to avoid bloat node modules across apps and minimize Docker images’ size.

I could be missing something from the doc. Any clues, corrections, or future plans sharing will be appreciated. Thanks in advanced =]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
larixercommented, Jul 4, 2020

@ivawzh Yarn 2 has much better way to support multi-app workflow than fragile and confusing nohoist. You can use yarn workspaces focus command inside apps/web-service-a when you are going to install it inside Docker. This will install apps/web-service-a dependencies and shared modules dependencies it depends on and will NOT install search-service-b and admin-service-c dependencies. The subset of installed dependencies will be properly deduplicated and hoisted into root node_modules dir if you are using node-modules linker. This same yarn workspaces focus approach works for multi-app pnp projects as well. The relevant docs are here: https://yarnpkg.com/cli/workspaces/focus

0reactions
LvChengbincommented, Jan 20, 2022

What if I want to remove unrelated workspaces at the same time?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-app Monorepo? · Discussion #462 · npm/rfcs - GitHub
My monorepo has two apps, "a" and "b". They're in an apps workspace and they both depend on a package "c" that's in...
Read more >
A Guide to Monorepos for Front-end Code - Toptal
A monorepo or monorepository is a code management and architectural concept whereby you keep all your isolated bits of code inside one super...
Read more >
Set Your Multi-App Environment up in 5 Minutes - Dev Genius
Nx CLI will prompt you to name a workspace ('shop' in our case), choose the workspace type ('react' in our case), type a...
Read more >
How to Share Code between JavaScript Apps - Fireship
In this lesson, I will show you how to use NPM packages to share code in a big JavaScript project that contains multiple...
Read more >
Turning a Node.js Monolith into a Monorepo without ... - InfoQ
Splitting monoliths into services creates complexity in maintaining multiple repositories (one per service) with separate (yet interdependent) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found