-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
docs: add debugging/troubleshooting guide #5212
Open
nettyso
wants to merge
3
commits into
yarnpkg:master
Choose a base branch
from
nettyso:debuggingdocsdocsdocs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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,120 @@ | ||
--- | ||
category: advanced | ||
path: /advanced/debugging | ||
title: "Debugging Quickstart" | ||
description: Debug internal errors in Yarn without building from source. | ||
--- | ||
|
||
If you're experiencing an internal error with Yarn Berry you can download an unminified release from the GitHub CI artifacts to gather more information and attach a debugger. This does not require cloning the Yarn Berry repo or building from source. | ||
|
||
Let's say you run into an issue running `yarn` such as: | ||
|
||
``` | ||
❯ yarn config -v | ||
Internal Error: Expected value ([object Object]) to be a string in /home/you/some_repo/.yarnrc.yml (in /home/you/some_repo/.yarnrc.yml) | ||
at /home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:17330 | ||
at jk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:17626) | ||
at Vk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:16917) | ||
at dPe (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:18512) | ||
at jk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:17045) | ||
at Vk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:16917) | ||
at pPe (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:18174) | ||
at jk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:17013) | ||
at Vk (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:16917) | ||
at dPe (/home/you/some_repo/.yarn/releases/yarn-3.3.0.cjs:391:18512) | ||
❯ | ||
``` | ||
|
||
This doesn't say much because Yarn's code is minified to improve performance. Let's fix that! | ||
|
||
## Finding and using an unminified build of Yarn Berry | ||
|
||
Yarn is developed and released on GitHub, so we can fetch the unminified build there. Note there are references on npm and unpkg like "yarn@3.3.0" - they're not what we need. | ||
|
||
Start on the releases page: https://github.com/yarnpkg/berry/releases/ | ||
|
||
 | ||
|
||
Choose a release to download: | ||
|
||
 | ||
|
||
Find the CI pipeline that built the artifacts and navigate to its "Summary" tab. The artifacts are at the bottom of the page. | ||
|
||
 | ||
 | ||
 | ||
|
||
Unzip the artifacts and move the `yarn.js` somewhere memorable such as `<root>/.yarn/releases/yarn-3.3.0-github-artifact.js`. Finally, point your `.yarnrc.yml` to this new release: | ||
|
||
```yml | ||
# yarnPath: .yarn/releases/yarn-3.3.0.cjs | ||
yarnPath: .yarn/releases/yarn-3.3.0-artifact.js | ||
``` | ||
|
||
Re-running the bug now shows more readable stacktraces: | ||
|
||
``` | ||
❯ yarn config -v | ||
Internal Error: Expected value ([object Object]) to be a string in /home/you/some_repo/.yarnrc.yml (in /home/you/some_repo/.yarnrc.yml) | ||
at interpretValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70705:15) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70724:25) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseMap (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70756:34) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70695:16) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseShape (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70742:28) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70693:16) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseMap (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70756:34) | ||
❯ | ||
``` | ||
|
||
You'll notice that this is looping and it's not the root of the stack. We can fix this by passing the Node.js flag `--stack-trace-limit=` (which is *not* a flag for Yarn itself): | ||
|
||
``` | ||
❯ NODE_OPTIONS="--stack-trace-limit=100" yarn config -v | ||
Internal Error: Expected value ([object Object]) to be a string in /home/you/some_repo/.yarnrc.yml (in /home/you/some_repo/.yarnrc.yml) | ||
at interpretValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70705:15) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70724:25) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseMap (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70756:34) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70695:16) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseShape (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70742:28) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70693:16) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at parseMap (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70756:34) | ||
at parseSingleValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70695:16) | ||
at parseValue (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70683:16) | ||
at _Configuration.use (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:71153:20) | ||
at _Configuration.useWithSource (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:71122:14) | ||
at Function.find (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:70991:23) | ||
at async exec (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:77304:29) | ||
at async run (/home/you/some_repo/.yarn/releases/yarn-3.3.0-artifact.js:77291:9) | ||
❯ | ||
``` | ||
|
||
Great! | ||
|
||
This is definitely a configuration issue somewhere deep in our `.yarnrc.yml`, but it doesn't tell us what `[Object object]` is. We'll have debug this futher. Below are instructions for debugging Yarn with VSCode. | ||
|
||
## Debugging with VSCode | ||
|
||
Open VSCode's "JavaScript Debug Terminal" either via the Debug sidebar (shown below) or via Ctrl/Cmd+Shift+P. This terminal is special in that it will automatically attach a debugger to all invocations of Node.js. Type the `yarn` command and wait for the error. | ||
|
||
 | ||
|
||
If the debugger doesn't activate (there is no `Debugger attached` log message) for `yarn ...` you can try `node /path/to/yarn ...` where the path to your Yarn executable can be found from running `which yarn` i.e `node $(which yarn) config -v` in Bash/Unix. | ||
|
||
If the debugger activates but doesn't pause on the exception, try adding a breakpoint on the last line of the stacktrace by Ctrl+Cmd clicking on the location, i.e: `.../yarn-3.3.0-artifact.js:70705:15`, and then clicking the red circle 🔴 near the line number. | ||
|
||
Now inspect the value that Node is paused on: | ||
|
||
 | ||
|
||
Great! We can see that the issue was with identation in `.yarnrc.yml`: | ||
|
||
 | ||
|
||
Please submit your bug or open an MR! Happy debugging. |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole section can be replaced with a single command: