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.

Support for Yarn workspaces/monorepos

See original GitHub issue

First of all, thanks for the awesome work on this package!

I’ve started exploring the new “workspaces”/“monorepos” feature of Yarn (https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/), which enables “hoisting” of all node_modules from any sub-projects to a single parent repository (so that if you have sub-folders with individual package.jsons, each one would install its deps in the “parent” node_modules and link them, unless there are version conflicts).

However, patch-package no longer automatically applies patches to sub-project packages in its default configuration (i.e. when I run yarn in the parent folder, it only applies patches/ from the “parent” folder). I had to move all patches from sub-projects into the “parent” patches/ to make it work, however that sort of “pollutes” the “global” patch space with patches from sub-projects.

Are you familiar with this feature, and are there any other (better) solutions to enable automatic patching of sub-projects (I know it’s a lot to ask, was just hoping to hear your thoughts)?

Thanks again!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:19 (5 by maintainers)

github_iconTop GitHub Comments

21reactions
ds300commented, Apr 10, 2019

As of version 6.1.0 patch-package now works with yarn workspaces 🎉

The setup instructions are exactly the same, but you might need to set it up for sub packages in addition to the repo root package if you want to patch node_modules which were not hoisted.

9reactions
brunolemoscommented, Jan 18, 2019

I was also having trouble generating the patch on a yarn workspace, getting the error Error: ENOENT: no such file or directory, unlink (same as @vieira posted above).

Here’s my current workaround:

EDIT: As @krzkaczor commented below, you don’t need to yarn add the package on root. Just manually add the entry in the package.json and that’s enough. Original comment:

  • yarn add package-name -W (Install the package on the root package.json)
  • yarn patch-package package-name (Generate the patch)
  • yarn remove package-name -W (Remove the package from the root package.json)

This way the patch will be successfully created. I didn’t face issues applying the patch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scaling out JavaScript Monorepos with Yarn Workspaces
A monorepo allows multiple applications to coexist in the same repository and cross-reference each other, easing the overhead of repository ...
Read more >
Workspaces in Yarn | Yarn Blog
Yarn Workspaces is the first step of what a package manager could do for managing monorepos as they become a more common solution...
Read more >
Yarn workspaces — monorepo beginner's guide - Medium
Yarn Workspaces is a feature that allows users to install dependencies from multiple package.json files in subfolders of a single root package.json file,...
Read more >
Yarn Workspaces - Monorepo Approach - DEV Community ‍ ‍
Yarn Workspaces is a feature that allows users to install dependencies from multiple package.json files in subfolders of a single root package.
Read more >
Setting up React Native Monorepo with Yarn Workspaces
Setting up Yarn workspaces ... While setting up a monorepo, we have two options: we can either hoist the packages to the root...
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