Yarn: Yarn deletes contents of symlinked directories on install

Created on 13 Dec 2016  路  17Comments  路  Source: yarnpkg/yarn

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

What is the current behavior?
Symlinks manually created in node_modules disappear when running yarn install. This is fine.
However, it isn't just the symlink that gets deleted, but the entire contents of the directory that the symlink pointed to. Ouch.

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

  1. In a package, create a symlink, node_modules/the_link, pointing to /some/path/directory with some backed-up files in it.
  2. Run yarn install
  3. See node_modules/the_link is gone -- expected behavior.
  4. See some/path/directory is now empty -- not expected.

What is the expected behavior?
Only the symlink should be deleted.

Background
We're using this workflow in a monorepo to easily develop on packages. This is different from the yarn link workflow, because the links are always in place, not every once in a while. Currently we're fine with a gulp script to recreate them after yarn install, but losing changes is unacceptable. Other issues like #1214 and constantly using cached file: packages prevent using other options.

Please mention your node.js, yarn and operating system version.
yarn: 0.17.10
node: 4.3.2
osx: 10.12.1

Most helpful comment

This issue is spotted again with recent Yarn v1.5.1 on macOS 10.12.6 (16G1212)
I've lost quite a big chunk of new source code due to it.

Steps:
yarn init -y
yarn add moment
mkdir src
touch src/file.js
ln -s ../src node_modules/@link
ls src
yarn add ramda
ls src

Observe:
empty src dir

All 17 comments

I've got a slightly different problem that I think is related:

I have npm modules I'm developing on that I have linked globally by running yarn link inside each npm module directory. In the main project, I run yarn link <module-name> which works fine. However, running yarn install after that results in the contents of those npm modules being overwritten with whatever version of the module is required in the main project. This caused me to lose quite a bit of changes :/

If there is a symlink to / in node_modules folder, that mean you may loose everything that you have write access.

@acburdine we were experiencing the same thing (files in linked packages being overwritten when running yarn install). Updating to the latest release (v0.18.1) seems to have fixed the problem.

I'm also experiencing this with v0.18.1

my postinstall script is ln -sfn ../ ./node_modules/@

Running yarn version 0.19.1, the contents of a linked package are not overwritten. Therefore I don't get the behavior described by @acburdine.

This issue was causing me headaches. Can confirm I don't get the same problem in version 0.19.1.

I'm unable to point to a specific commit that fixed this, but I'm happy to close too.

Is this solved? I've got exactly the same problem today with yarn v0.27.5, loosing a lot of work...

I hit the issue again yesterday however I'm still on v0.24.5. This time it caught me unprepared and I had to write the code it wiped again.

Same issue with 0.27.5 just today

I can't reproduce this on latest master @jquense. May be try 0.28.0 or create a new issue with concrete repro steps?

I get this issue today. Problem is using manual symlink with ln .. command.

More info here https://gist.github.com/branneman/8048520#conclusion

  1. The Symlink
    If you're using CVS or SVN (but not Git!), this solution is a great one which works, otherwise I don't recommend this to anyone.

I'm going to use another solution.

@at-daonguyen can you try one of the more recent releases like 0.28.4 or one of the nightlies?

This issue is spotted again with recent Yarn v1.5.1 on macOS 10.12.6 (16G1212)
I've lost quite a big chunk of new source code due to it.

Steps:
yarn init -y
yarn add moment
mkdir src
touch src/file.js
ln -s ../src node_modules/@link
ls src
yarn add ramda
ls src

Observe:
empty src dir

Just got bit by this and lost a good deal of work, ugh...

Found this: #5709.Turns out that the problem is creating symlinks that begin with @. This is clearly a bug, but a workaround for now is to make sure you don't use @ at the start of your symlink name.

What the heck. This is insane! I had "@": "link:./src", in my package.json and my src directory kept getting deleted. Thank god I have version control, but this absolutely should never happen! Why not just unlink it? Why on earth would it try to delete what the link points to?

We are experiencing the same issue we have multiple Symlinks using the @ sign "@components": "link:./src/components/", and the directories just get deleted on yarn install. this is madness!

i've heard about this issues for 3 years! Ever think about actually fixing this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NonPolynomial picture NonPolynomial  路  3Comments

sebmck picture sebmck  路  3Comments

chiedo picture chiedo  路  3Comments

davidmaxwaterman picture davidmaxwaterman  路  3Comments

danez picture danez  路  3Comments