yarn icon indicating copy to clipboard operation
yarn copied to clipboard

`yarn unlink package` doesn't restore node_modules/package

Open wclr opened this issue 8 years ago • 11 comments

After yarn link package yarn creates symlink node_module/package, but after yarn unlink package it just removes node_module/package and not places there hard installed version.

Probably expected that it should find in cache or fetch a correct version from registry and replace removed symlink with it.

wclr avatar Nov 20 '16 05:11 wclr

Seem to be the same issue https://github.com/yarnpkg/yarn/issues/937

wclr avatar Nov 20 '16 07:11 wclr

+1, same issue here!

caesarsol avatar Dec 21 '16 07:12 caesarsol

From the docs (https://yarnpkg.com/en/docs/cli/unlink#toc-yarn-unlink-package) this seems to be expected behaviour. However, as noted in #937 running yarn does not add the package back to node_modules.

andybluntish avatar Dec 23 '16 01:12 andybluntish

Yes, it seems yarn check detects the package is missing, but yarn install does not restore it...

I have to run yarn install --force to make it right.

(As a possible improvement, I think unlink could reinstall the original package by itself)

caesarsol avatar Mar 22 '17 10:03 caesarsol

unlink should reinstall.

wclr avatar Mar 22 '17 12:03 wclr

it works with a force install, but it surprises me why it doesn't with a normal yarn install using 1.2.1

danielepiccone avatar Feb 16 '18 13:02 danielepiccone

Running yarn install --check-files seems to restore the package in v1.4.0.

stephencroberts avatar Mar 29 '18 00:03 stephencroberts

This has been going on since 2016? I'm having the same issue with yarn 1.12.3.

If a yarn install --check-files or a yarn install --force is required, we should at least being told so in the note after yarn unlink instead of saying we only need to do a normal yarn install.

remino avatar Dec 26 '18 02:12 remino

I don't think yarn unlink package is meant to trigger an install (or at least, I'd feel uncomfortable changing this behavior anywhere else than in a major release). In the case where multiple packages are linked / unlinked (mostly scripts), running an new install every time would cause a perf hit.

That said, yarn install not noticing that a link disappeared is a bug. I don't have time right now to work on this, but #6931 seems an acceptable workaround for the time being (except that I'd recommend to use --force rather than --check-files, since the later has long-term effects).

arcanis avatar Jan 23 '19 12:01 arcanis

I just switched my terminal to Windows PowerShell and all works)

MykhailoTurokCoax avatar Oct 14 '21 06:10 MykhailoTurokCoax

None of the suggestions above work for yarn v2 or v3 - most of those flags don't even exist. The only option is the going nuclear:

rm -rf node_modules 
yarn

dalmo3 avatar Jun 11 '22 00:06 dalmo3