Skip to content
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

Yarn crashes whenever there is a .yarnrc.yml that is not empty but does not set any YAML nodes #8965

Closed
kalrish opened this issue Jun 26, 2023 · 1 comment

Comments

@kalrish
Copy link

kalrish commented Jun 26, 2023

Issue

The corresponding issue template did not set a structure. I can edit this issue's description to match the new repository's issue template for bug reports.

Affected versions

I have run into this issue with version 1.22.19 of Yarn as distributed by Arch Linux on version 20.2.0 of Node.js as distributed by Arch Linux:

pacman --query --owns -- "$(which -- node)"
/usr/bin/node is owned by nodejs 20.2.0-1
pacman --query --owns -- "$(which -- yarn)"
/usr/bin/yarn is owned by yarn 1.22.19-1

Reproduction

Yarn runs fine when there is no .yarnrc.yml:

ls -A
yarn --version
1.22.19

Yarn runs fine when there is an empty .yarnrc.yml:

touch -- .yarnrc.yml
yarn --version
1.22.19

Yarn runs fine when there is a .yarnrc.yml with a single line feed (LF) character:

echo > .yarnrc.yml
yarn --version
1.22.19

Yarn crashes when there is a .yarnrc.yml with two line feed (LF) characters:

echo >> .yarnrc.yml
yarn --version
TypeError: Cannot read properties of null (reading 'yarnPath')
    at loadRcFile (/usr/lib/node_modules/yarn/lib/cli.js:56995:49)
    at /usr/lib/node_modules/yarn/lib/cli.js:56966:14
    at /usr/lib/node_modules/yarn/lib/cli.js:97395:14
    at Array.map (<anonymous>)
    at parseRcPaths (/usr/lib/node_modules/yarn/lib/cli.js:97393:78)
    at Object.findRc (/usr/lib/node_modules/yarn/lib/cli.js:97407:10)
    at getRcConfigForCwd (/usr/lib/node_modules/yarn/lib/cli.js:56965:74)
    at /usr/lib/node_modules/yarn/lib/cli.js:88756:56
    at Generator.next (<anonymous>)
    at step (/usr/lib/node_modules/yarn/lib/cli.js:310:30)

Yarn crashes when there is a .yarnrc.yml with only a comment:

echo '# foobar' > .yarnrc.yml
yarn --version
TypeError: Cannot read properties of null (reading 'yarnPath')
    at loadRcFile (/usr/lib/node_modules/yarn/lib/cli.js:56995:49)
    at /usr/lib/node_modules/yarn/lib/cli.js:56966:14
    at /usr/lib/node_modules/yarn/lib/cli.js:97395:14
    at Array.map (<anonymous>)
    at parseRcPaths (/usr/lib/node_modules/yarn/lib/cli.js:97393:78)
    at Object.findRc (/usr/lib/node_modules/yarn/lib/cli.js:97407:10)
    at getRcConfigForCwd (/usr/lib/node_modules/yarn/lib/cli.js:56965:74)
    at /usr/lib/node_modules/yarn/lib/cli.js:88756:56
    at Generator.next (<anonymous>)
    at step (/usr/lib/node_modules/yarn/lib/cli.js:310:30)

Yarn seems to crash whenever there is a .yarnrc.yml that is not empty but does not set any nodes.

I wrote a reproduction case for Sherlock following the guide:

const fs = require("node:fs");

fs.writeFileSync(
    ".yarnrc.yml",
    "\n",
);

expect(
    yarn(
        "--version",
    ),
)
.resolves
.not
.toThrow(
)
;

Contribution

I would like to propose a fix. Please let me know whether one is desired or this issue does not warrant an update to the otherwise frozen Yarn Classic.

@merceyz
Copy link
Member

merceyz commented Nov 14, 2023

Fixed in #9009

@merceyz merceyz closed this as completed Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants