-
Notifications
You must be signed in to change notification settings - Fork 2k
docs(errors): improve error message for recursive calls #9650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ebd7912
docs(errors): Improve error message for recursive calls.
anthonyshew d96bad1
WIP
anthonyshew 4b99a84
WIP
anthonyshew b172c7f
WIP
anthonyshew e6bfadf
Update crates/turborepo-lib/src/task_graph/visitor/mod.rs
anthonyshew a1752be
WIP
anthonyshew ccf32db
WIP
anthonyshew 5ace1f5
Update turborepo-tests/integration/tests/recursive-turbo.t
anthonyshew 6dac309
Update turborepo-tests/integration/tests/recursive-turbo.t
anthonyshew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.