Yarn: Symlinking packages may lead to invalid states

Created on 13 Oct 2016  路  10Comments  路  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?

Bug.

What is the current behavior?

An unlinked (but added) package is missing from node_modules and yarn will not install.

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

  1. Link a random package

git clone [email protected]:tj/co.git cd co && yarn link

As a side note, yarn will not install the package's dependencies. The default npm client would do that. I'm not sure whether that's expected or not given that the linking process is slightly different already.

  1. Create a new directory and use the linked package from there

yarn link co

  1. Add the package again but this time via add

yarn add co

The linked package is still used at this point (and that's consistent with the default client).

  1. Unlink the package

yarn unlink co

This will remove the link from node_modules as expected.

  1. Run yarn to get the added (locked) package back

```
yarn
yarn install v0.15.1
warning No license field
success Already up-to-date.
Done in 0.13s.

ls node_modules
```

At this point, the package is not present in node_modules but yarn seems to be okay with that and won't install it. Doing yarn add co again _will_ install it.

What is the expected behavior?

The package should be installed after unlinking it and running yarn.

Please mention your node.js, yarn and operating system version.

Node.js 6.7.0
Yarn 0.15.1
Ubuntu 12.04

cat-bug good first issue help wanted needs-confirmation triaged

Most helpful comment

The following command was a sufficient workaround for me:

yarn install --check-files

https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-check-files

All 10 comments

This still seems to be an issue with yarn v0.18.1.

@andybluntish only workaround I've found is to either delete the node_modules folder entirely, or to yarn add something then revert changes.

You can also workaround by deleting yarn.lock, instead of nuking node_modules

The following command was a sufficient workaround for me:

yarn install --check-files

https://yarnpkg.com/en/docs/cli/install#toc-yarn-install-check-files

Can repro.
The problem is in linkedModules field in node_modules/.yarn-integrity.
Yarn would ignore a missing folder if it is a modules globally registered as linked.

It should at least check if symlink exists

I feel like @arcanis addressed this in PR not too long ago. @arcanis can you confirm?

Any updates here?

I can still reproduce this with 1.8.0

PS my-scripts> yarn unlink @gongt/stillalive
yarn unlink v1.12.1
success Removed linked package "@gongt/stillalive".
info You will need to run `yarn` to re-install the package that was linked.
Done in 0.10s.
PS my-scripts> yarn
yarn install v1.12.1
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.20s.
PS my-scripts> dir .\node_modules\@gongt\
PS my-scripts>

Still problem v1.12.1

Hi @arcanis . Based on the comments in https://github.com/yarnpkg/yarn/issues/1957 and https://github.com/yarnpkg/yarn/pull/6931, I think this issue should be reopened. The messaging is better now, but ultimately a yarn install should restore any unliked packages.

Was this page helpful?
0 / 5 - 0 ratings