Yarn: Yarn link does not work

Created on 6 Jan 2019  Â·  14Comments  Â·  Source: yarnpkg/yarn

This is a bug report

Current behavior, and step to produce:

To illustrate the problem (bug) I have created a sample repo, which you can find at:
https://github.com/ApolloTang/issue-yarn-link-does-not-work

It has two folders: one has content which is the dependency package, the other a project that using the dependency package:

~/1/1-a/16-tools/yarn-link/issue-yarn-link-does-not-work
$ tree -F
.
├── dependency/
│   ├── index.js
│   ├── node_modules/
│   ├── package.json
│   └── yarn.lock
└── using-dependency/
    ├── index.js
    └── package.json

in dependency/ folder:

$ yarn link

screenshot:

screen shot 2019-01-06 at 1 37 07 pm

This created a link in my ~/.config/yarn/link.
To confirm this :

cd ~/.config/yarn/link; ls -l 

screenshot:

screen shot 2019-01-06 at 1 26 54 pm

My ~/.config/yarn has the following structure:

screenshot:
screen shot 2019-01-06 at 2 04 47 pm

From the above the link is indeed pointing to my dependency folder. To confirm:

screenshot:

screen shot 2019-01-06 at 1 31 24 pm

Now that the link has created I can cd to the project folder to link the dependency; However, I got

error No registered package found called ....

screenshot:

screen shot 2019-01-06 at 1 41 38 pm

I also notice that if I go back to the dependency package folder, yarn can not unlink the package:

screenshot:

screen shot 2019-01-06 at 1 50 52 pm

It seem like yarn link does not know where the directory~/.config/yarn/link is.

Here is the output of my yarn config list:

screen shot 2019-01-06 at 2 01 06 pm

Here is the content of my .yarnrc:

screen shot 2019-01-06 at 2 00 11 pm

Here is my environment:

screenshot:
screen shot 2019-01-06 at 2 10 51 pm

triaged

Most helpful comment

It seems I found why it is not working as expect. My ~/.config is a symlink, so the the symlink which yarn generate is totally wrong in a symlink folder. After making ~/.config to a real folder, everything works well!

All 14 comments

duplicate of #1297 as "re-reported" by @cobyism, @fugufish, @JimmyCDChen and other.

  • tried yarn link dependency (without quote) does not work [suggested by @travomic]
  • tried yarn build in dependency folder does not work, there is no such command yarn build [suggested by @sandalsoft]
  • using sudo does not work [suggested by @ConAntonakos]

the symbolic link is created in .config/yarn/link/ after all, but yarn link command could not find it, could it be related to #2334, since I am using .config (XDG specification)?

probably related: #6801

This issue also started happening for me. On yarn version 1.12.3

For me, it looks like the path that is set for the symbolic link is the absolute path prefixed with '../''s. Once this is fixed, yarn link works.

Jan 18 2020 - still happening.

ls -l symlink says ../../../../../../absolute/path/here

What a bother.

The same problem, can not resolve the module even if the link is created.
version 1.21.1

I had the same problem. Only that, it was working few days ago. Later, when I changed the directory of my project, it stopped working. I tried linking again and it showed linked successfuly. Still, it throws a module not found error.

Same problem using lerna.

For a temporary solution, you can direct link by providing direct paths wherever you import that particular module and then rebuild the whole project.

import​ ​ CornerstoneViewport​ ​ from
'../../../react-cornerstone-viewport-2.1.0/src/CornerstoneViewport/Corn
erstoneViewport'​ ;

For a temporary solution, you can direct link by providing direct paths wherever you import that particular module and then rebuild the whole project.

import​ ​ CornerstoneViewport​ ​ from
'../../../react-cornerstone-viewport-2.1.0/src/CornerstoneViewport/Corn
erstoneViewport'​ ;

One other solution ( works but not always)
Add the repository name in the projects node modules folder ( directly along with the version) and rebuild.

A temporary solution I thought was to use file:path in package.json ... could be a better solution and avoid the various paths in the imports

It seems I found why it is not working as expect. My ~/.config is a symlink, so the the symlink which yarn generate is totally wrong in a symlink folder. After making ~/.config to a real folder, everything works well!

yes, my .config is a symlink !

I have a 'real' ~/.config dir, and yarn link is not working correctly.

Only I get no error messages. Or any other messages.
Screen Shot 2020-07-02 at 11 48 58 AM

(I had to use Activity Monitor to SIGKILL node, as ctrl+c was leaving the webpack-dev-server up, because reasons, I assume.)

The ui-kit (celula) builds just fine, and todos builds just fine without the kit.

Was this page helpful?
0 / 5 - 0 ratings