[Bug] Yarn nested workspaces feature conflicts with sandboxed build systems
See original GitHub issueBug description:
Nested workspaces don’t play nice with sandboxed build systems. If the build directory is stored in a subdirectory in the repo (and that’s often the case), yarn will not allow running commands inside it because it will detect the “package.json” in the repo above and will complain that the build directory is not a workspace of the project.
Repro steps:
- Create a yarn monorepo with
workspaces: ['packages/*']
- Add some package inside
packages/
mkdir .build
in the project root- Now copy the whole project into the
.build
directory cd
into.build
and runyarn
You will get an error looking roughly like this:
Usage Error: This command can only be run from within a workspace of your project (plz-out/tmp/third_party/yarn_registry/build_registry._build isn't a workspace of /Users/snowak/test_repo/package.json).
Environment:
- OS: macOS
- Node version: v13.11.0
- Yarn version: 2.0.0-rc.30
Additional context
I’m not actually sure how it could be resolved and whether it should be resolved. Nevertheless, it’s a real issue I encountered when trying out the Please build system, so it’s going to bite other people too.
Perhaps there should be a CLI argument that would allow providing the project root path manually? This way yarn wouldn’t keep looking upwards and wouldn’t find the actual repo.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
That’s certainly a valid option, but speaking from the perspective of a user who encountered this issue - I had no idea the error list page exists but I did read the article about workspaces thoroughly. I knew what the error meant so I didn’t have to look it up, I was looking for a solution, not an explanation of the error. I knew I needed a way to set “boundaries” on the folder structure for workspaces, so I went to the article about workspaces.
Anyway, that’s my way of approaching problems, I’m sure others do it differently so ideally the escape hatch would be mentioned in both places 😃
Thanks @arcanis, the solution you suggested worked for me.
It would be great if this feature was documented somewhere on this page: https://yarnpkg.com/features/workspaces