-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(errors): improve error message for recursive calls (#9650)
Closes #9224 ### Description This is a state that you can get into two ways: - Genuinely configuring their way into a loop with misconfigured scripts and tasks - Accidentally misconfiguring their package manager Workspace - In some misconfigurations, the Workspace will look like a single-package Workspace, but the previous iteration of our error message didn't give any hints about this. Either way, we should be providing an informative error message, so this PR provides a message that caters to both situations. We'll need a more verbose explanation, so an error link has been added here, as well. ### Testing Instructions Delete `pnpm-workspace.yaml` from `create-turbo`, remove `turbo` from `devDependencies`, re-run package manager installation, and try to run `turbo build`. You should be greeted by this new and improved error message. --------- Co-authored-by: Chris Olszewski <[email protected]>
- Loading branch information
1 parent
1a94894
commit 7a92d0b
Showing
4 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
title: Recursive `turbo` invocations | ||
description: Learn more about errors with recursive sccripts and tasks in Turborepo. | ||
--- | ||
|
||
## Why this error occurred | ||
|
||
When a cycle of `turbo` invocations is detected in a [single-package workspace](https://turbo.build/repo/docs/guides/single-package-workspaces), Turborepo will error to prevent the recursive calls to itself. Typically, this situation occurs for one of two reasons: | ||
|
||
### Recursion in scripts and tasks | ||
|
||
In a single-package workspace, a script in `package.json` that calls a Turborepo task with the same name causes a loop. | ||
|
||
```json title="./package.json" | ||
{ | ||
"scripts": { | ||
"build": "turbo run build" | ||
} | ||
} | ||
``` | ||
|
||
Calling the `build` script calls `turbo run build`. `turbo run build` then calls the `build` script, initiating the loop of recursive calls. | ||
|
||
To resolve this, ensure that the name of the script in `package.json` is not the same as the Turborepo task. For example, to fix the snippet above, renaming the script would break the cycle: | ||
|
||
```json title="./package.json" | ||
{ | ||
"scripts": { | ||
"build:app": "turbo run build" | ||
} | ||
} | ||
``` | ||
|
||
### Package manager Workspace misconfiguration | ||
|
||
A misconfigured workspace can make it appear that a [multi-package workspace](https://vercel.com/docs/vercel-platform/glossary#multi-package-workspace) is a single-package workspace. This causes Turborepo to infer that the repository is of the wrong type, causing it to see the script in `package.json` to be recursive. | ||
|
||
Your repo can end up in this state in a few ways, with the most common being that the [packages are not defined according to your package manager](https://turbo.build/repo/docs/crafting-your-repository/structuring-a-repository#specifying-packages-in-a-monorepo). An npm workspace that is missing the `workspaces` field in `package.json` or a pnpm workspace that is missing a `pnpm-workspace.yaml` file can result in this error message. | ||
|
||
Check that your repository is complying with standards for multi-package workspaces and correct any issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters