Skip to content

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

@kalrish

Description

@kalrish

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions