turbo: [turborepo] ERROR run failed: Failed to add workspace ""
What version of Turborepo are you using?
1.7.0
What package manager are you using / does the bug impact?
pnpm
What operating system are you using?
Mac
Describe the Bug
Following upgrading from 1.6.3 to 1.7.0 I have noticed that turbo now consistently fails to run my deployment command giving the following error:
> turborepo-basic-shared@0.0.0 deploy:dev /home/runner/work/monorepo/monorepo
> turbo run deploy:dev --continue --ignore="pnpm-lock.yaml"
ERROR run failed: Failed to add workspace "" from apps/website/.next, it already exists at apps/customer-portal/.next
Turbo error: Failed to add workspace "" from apps/website/.next, it already exists at apps/customer-portal/.next
ELIFECYCLE Command failed with exit code 1.
Error: Process completed with exit code 1.
This is being run in GitHubActions on a standard ubuntu image. The build command runs ok (which runs this script in the two affected workspaces: "build:export": "next build && next export",.
The turbo command which is failing is supposed to run this script command in the workspaces: "deploy": "cdk deploy --all --require-approval never --outputs-file ./cdk-outputs.json -c env=production && ts-node cdk/helpers/upload-source-maps.ts",
Expected Behavior
The command should execute successfully, as it was doing in 1.6.3.
To Reproduce
I’m unsure as I am not clear on the cause. I did notice that some changes were made in 1.7.0 which affect how workspaces are parsed, perhaps this has introduced a problem when using pnpm?
Reproduction Repo
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 8
- Comments: 20 (10 by maintainers)
Commits related to this issue
- chore(dev-deps): Revert turbo to 1.6.x while https://github.com/vercel/turbo/issues/3340 — committed to ecomplus/cloud-commerce by leomp12 a year ago
- chore(package.json): add `name` field within all `package.json` Turborepo identifies each workspace in the monorepo by its package name. Workspaces with no `name` field are identified as empty string... — committed to sounisi5011/npm-packages by sounisi5011 a year ago
- build(npm-scripts): introduce Turborepo (#666) * build(npm-scripts): introduce Turborepo Introduce a new build system Turborepo that caches based on file content. see https://turbo.build/... — committed to sounisi5011/npm-packages by sounisi5011 a year ago
That was really helpful @c-kirkeby, thank you!
You solved the bug! (at least yours, that is).
As mentioned in the
pnpmdocs,packages/**means “all subdirectories”. Once an app has built, your workspace declaration is picking upapps/docs/.nextas a workspace.#2659 exposed the bug that all these workspaces are being added into Turbo’s graph. However, since they don’t define any
scriptsand are not dependencies of anything, they are always skipped over during all execution. Our new check for duplicate workspaces is inadvertently catching this issue.There are a few things we can do:
Ignore declared “workspaces” that are in
.gitignoredirectories.I need to dig into
pnpmitself to see how (and if) it does this, but our implementation is just expanding the globs at the moment: https://github.com/vercel/turbo/blob/552768bae0f92d716c3b6ea927502251be2992a3/cli/internal/packagemanager/packagemanager.go#L154#3375.
We can simply add a check for missing names. I think this is the wrong fix, because we shouldn’t have any of these in the first place. Based on this bug, I’m also concerned that large monorepos with a lot of Next.js apps that are misconfigured like this are bloating the graph unnecessarily.
We could revert the check for duplicate names.
I also believe this is the wrong solution, as duplicate workspace names will overwrite each other, and it’s valuable to check against that.
I’ll float this to the rest of the team, but in the meantime, this should fix your issue:
I’ve solved this issue by adding the following ignore rules to my
pnpm-workspace.yamlfile, according to PNPM docs:Please find the repo here: https://github.com/c-kirkeby/turbo-next-reproduction
This was created simply by using
pnpm create turbocommand, pickingpnpmas the package manager. I noticed it seems to only be happening when I change thepnpm-workspace.yamlpattern from- "apps/*to- "apps/**". I hope that helps!The issue is replicated by running
pnpm buildtwice.Hey all! Apologies for the inconvenience, and thanks for the reports!
Can you confirm that in each of your cases, the two workspaces mentioned int he error message are both missing the
namefield in their respectivepackage.jsonfiles?I’m submitting a “fix” in #3375, but it actually feels like creating a worse bug to fix this. As you may be able to tell, our WorkspaceGraph uses the name of the workspace to keep track of it. Workspaces with the same name (even if they are
""will overwrite each other in the graph). I’m surprised this hasn’t manifested as a much worse bug for you in some other way.In any case, it seems like things were “working” for you before. Could you confirm that
namekeys to each workspace “fixes” the issuenames to each workspaceIf the last one is true, I’d love to hear why as well. We may need to consider using switching to paths instead of names, if that’s the case.
Sadly does not work yarn or npm
Thanks for the workaround options. I can confirm that @c-kirkeby you workaround works for me (changing
pnpm-workspace.yamlfromapps/**toapps/*for example). It’s worth noting that depending on your implementation there may be undesired effects of doing this - but for me it’s a good solution.@mehulkar I think both of the options you’ve suggested are good. Improving error messaging is always helpful. But ignoring git ignored paths makes a lot of sense to me and is, I think, fairly intuitive as well.
I think we should warn on a detected package with a missing name, exclude it from the graph, and continue (don’t panic).