Notes

Setting Yarn config defaults globally

Edit on GitHub

Node
2 minutes
  • Check existing config with yarn config list
  • If you run the command to list config with a --verbose flag, it tells you which files it looked into for config and which ones it loaded from yarn config list --verbose
  • The global config is save in ~/.yarnrc.yml (Yarn 2.0 onwards. previously it was called .yarnrc)
  • if you set a config flag in a dir where there is no .yarnrc.yml, it’ll add the config to the global config file at ~/.yarnrc.yml
1# yarn config set <key> <value> [-g|--global]
2
3yarn config set init-license 'CC-BY-SA-4.0' -g
4yarn config set init-version '0.0.1' -g
  • unlike setting npm defaults, the -g flag must come at the end of the command.
  • init-author-name, init-author-email, and init-author-url are not available
 1# yarn config list
 2
 3yarn config v1.22.10
 4info yarn config
 5{
 6  'version-tag-prefix': 'v',
 7  'version-git-tag': true,
 8  'version-commit-hooks': true,
 9  'version-git-sign': false,
10  'version-git-message': 'v%s',
11  'init-version': '0.0.1',
12  'init-license': 'CC-BY-SA-4.0',
13  'save-prefix': '^',
14  'bin-links': true,
15  'ignore-scripts': false,
16  'ignore-optional': false,
17  registry: 'https://registry.yarnpkg.com',
18  'strict-ssl': true,
19  'user-agent': 'yarn/1.22.10 npm/? node/v14.16.0 darwin arm64',
20}
21info npm config
22{}
23✨  Done in 0.01s.
 1# yarn config list --verbose
 2yarn config v1.22.10
 3verbose 0.128760292 Checking for configuration file "/Users/aamnah/Sites/.npmrc".
 4verbose 0.1288705 Checking for configuration file "/Users/aamnah/.npmrc".
 5verbose 0.128933125 Checking for configuration file "/Users/aamnah/.nvm/versions/node/v14.16.0/etc/npmrc".
 6verbose 0.128995583 Checking for configuration file "/Users/aamnah/Sites/.npmrc".
 7verbose 0.129038833 Checking for configuration file "/Users/aamnah/.npmrc".
 8verbose 0.129080542 Checking for configuration file "/Users/.npmrc".
 9verbose 0.129333083 Checking for configuration file "/Users/aamnah/Sites/.yarnrc".
10verbose 0.129394208 Checking for configuration file "/Users/aamnah/.yarnrc".
11verbose 0.129435708 Found configuration file "/Users/aamnah/.yarnrc".
12verbose 0.129813583 Checking for configuration file "/Users/aamnah/.nvm/versions/node/v14.16.0/etc/yarnrc".
13verbose 0.129904458 Checking for configuration file "/Users/aamnah/Sites/.yarnrc".
14verbose 0.129972667 Checking for configuration file "/Users/aamnah/.yarnrc".
15verbose 0.13001825 Found configuration file "/Users/aamnah/.yarnrc".
16verbose 0.130115708 Checking for configuration file "/Users/.yarnrc".
17verbose 0.131106792 current time: 2021-02-26T06:25:40.816Z
18info yarn config
19{
20  'version-tag-prefix': 'v',
21  'version-git-tag': true,
22  'version-commit-hooks': true,
23  'version-git-sign': false,
24  'version-git-message': 'v%s',
25  'init-version': '0.0.1',
26  'init-license': 'CC-BY-SA-4.0',
27  'save-prefix': '^',
28  'bin-links': true,
29  'ignore-scripts': false,
30  'ignore-optional': false,
31  registry: 'https://registry.yarnpkg.com',
32  'strict-ssl': true,
33  'user-agent': 'yarn/1.22.10 npm/? node/v14.16.0 darwin arm64',
34}
35info npm config
36{}
37✨  Done in 0.01s.

Alternatively, you can set the config in ~/.yarnrc.yml

1# ~/.yarnrc.yml (Yarn 2.0 berry)
2
3initLicense: 'CC-BY-SA-4.0'
4initVersion: '0.0.1'