Yarn: `yarn config delete yarn-path` doesn't work if yarn-path is invalid

Created on 9 Jan 2019  ·  3Comments  ·  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
If your yarn-path setting points to a path that doesn't exist, all yarn commands will fail with an error like this:

module.js:550
    throw err;
    ^

Error: Cannot find module '/foo/.yarn/releases/yarn-1.13.0.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3

This makes sense in most cases: if the user specified a bad yarn-path, then yarn should bail and let the user fix it. But one area where it leads to a bad experience is with yarn policies.

It's common to run yarn policies set-version and commit the results to a feature branch. But, assuming .yarnrc isn't checked in (https://github.com/yarnpkg/yarn/issues/4134), switching branches will result in an invalid yarn-path pointing to a non-existing file. If you happen to know that yarn policies is implemented on top of yarn-path, you may try to yarn config delete yarn-path, but that also loads yarn-path and thus will fail with a module not found error. The only thing you can do in this situation is manually edit .yarnrc.

If the current behavior is a bug, please provide the steps to reproduce.

  1. yarn policies set-version
  2. rm -rf .yarn/releases
  3. yarn config delete yarn-path

What is the expected behavior?
Not sure what the best behavior is, but some things that come to mind:

  • If yarn-path is invalid, log a warning and fallback to standard yarn path
  • Better error messaging when loading module at yarn-path fails. E.g. something that says "update your yarn-path in .yarnrc".

Please mention your node.js, yarn and operating system version.
node: 8
yarn: 1.13.0
OS: macOS

triaged

Most helpful comment

This problem can be fixed by removing yarn-path: foo-bar from your ~/.yarnrc.

Or you could just delete ~/.yarnrc.

(I only just found out there is a global .yarnrc placed in your home folder.)

All 3 comments

I'm having the same issue after setting a version to 1.10.1. Now I have no way of re-setting the version to anything else. I've tried deleting everything in ~/.yarn and reinstalling yarn but I keep getting the same error message.

Is there any way to un-set this policy?

/ $:yarn
-bash: yarn: command not found
/ $:curl -o- -L https://yarnpkg.com/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7041    0  7041    0     0  32586      0 --:--:-- --:--:-- --:--:-- 32447
Installing Yarn!
> Downloading tarball...

[1/2]: https://yarnpkg.com/latest.tar.gz --> /var/folders/89/q9hb3khx5d59bsft5yksf4qw0000gp/T/yarn.tar.gz.XXXXXXXXXX.JA8tC3xH
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    93  100    93    0     0    547      0 --:--:-- --:--:-- --:--:--   550
100   609    0   609    0     0    899      0 --:--:-- --:--:-- --:--:--   899
100 1142k  100 1142k    0     0   472k      0  0:00:02  0:00:02 --:--:--  825k

[2/2]: https://yarnpkg.com/latest.tar.gz.asc --> /var/folders/89/q9hb3khx5d59bsft5yksf4qw0000gp/T/yarn.tar.gz.XXXXXXXXXX.JA8tC3xH.asc
100    97  100    97    0     0    941      0 --:--:-- --:--:-- --:--:--   941
100   613    0   613    0     0   1905      0 --:--:-- --:--:-- --:--:--  1905
100   832  100   832    0     0   1657      0 --:--:-- --:--:-- --:--:--  1657
> Verifying integrity...
gpg: 水 12/19 01:04:55 2018 JSTに施された署名
gpg:                RSA鍵E21930C4D0A4AA4618581F7AE074D16EB6FF4DE3を使用
gpg: "Yarn Packaging <[email protected]>"からの正しい署名 [不明の]
gpg: 注意: この鍵は期限切れです!
 主鍵フィンガープリント: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
 副鍵フィンガープリント: E219 30C4 D0A4 AA46 1858  1F7A E074 D16E B6FF 4DE3
> GPG signature looks good
> Extracting to ~/.yarn...
> Adding to $PATH...
> We've added the following to your /Users/sen/.bash_profile
> If this isn't the profile of your current shell then please add the following to your correct profile:

export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

module.js:550
    throw err;
    ^

Error: Cannot find module '/Users/sen/.yarn/releases/yarn-1.10.1.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
> Yarn was installed, but doesn't seem to be working :(.

Just remove the yarn-path line from the yarnrc that's in your project

This problem can be fixed by removing yarn-path: foo-bar from your ~/.yarnrc.

Or you could just delete ~/.yarnrc.

(I only just found out there is a global .yarnrc placed in your home folder.)

Was this page helpful?
0 / 5 - 0 ratings