yarn
yarn copied to clipboard
Yarn link does not work
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:
This created a link in my ~/.config/yarn/link
.
To confirm this :
cd ~/.config/yarn/link; ls -l
screenshot:
My ~/.config/yarn
has the following structure:
screenshot:
From the above the link is indeed pointing to my dependency folder. To confirm:
screenshot:
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:
I also notice that if I go back to the dependency package folder, yarn can not unlink the package:
screenshot:
It seem like yarn link
does not know where the directory~/.config/yarn/link
is.
Here is the output of my yarn config list
:
Here is the content of my .yarnrc
:
Here is my environment:
screenshot:
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 commandyarn 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.
(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.
I have a similar problem with yarn link, I'm linking my own library framework
in my project client
This is the error message:
Could not load /Users/x/framework/node_modules/@babel/runtime/helpers/interopRequireDefault (imported by ../framework/dist/index.js): ENOENT: no such file or directory, open '/Users/x/framework/node_modules/@babel/runtime/helpers/interopRequireDefault'
The file /Users/x/project/node_modules/@babel/runtime/helpers/interopRequireDefault
exists.
The compiled code by babel that triggers the above error is this line:
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
when I add the file extension, the error disappears:
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js");
I have the same problem if link it with npm and I haven't found the way to configure babel so that it includes the file extension. The solution was to link it through the package.json like this:
"dependencies": {
"framework": "link:../framework"
}
I also encountered this issue with 1.22.10 where my ~/.config
is a symlink and although a symlink is created in ~/.config/yarn/link
I am unable to register it (or unlink it). I symlink my ~/.config
to manage my dotfiles across development machines (I suspect this is the use case others are doing as well). Related issues: https://github.com/yarnpkg/yarn/issues/7614, https://github.com/yarnpkg/yarn/issues/7388, https://github.com/yarnpkg/yarn/issues/7377
Just figured out link is applied on yarn add
command only. If you already have the remote package installed and you link it to a local one, you won't have the local one installed even after removing yarn.lock etc.
The only solution for me is to yarn remove
the package and yarn add
again.
Just figured out link is applied on
yarn add
command only. If you already have the remote package installed and you link it to a local one, you won't have the local one installed even after removing yarn.lock etc.The only solution for me is to
yarn remove
the package andyarn add
again.
@existe-deja this is exactly what I needed. Thank you!
For anyone struggling yarn 3
on a private package
on your package
yarn link
Then on the repo you want the linked package
# p is for private package
yarn link -p ~/path/to/my/package
This will add this line to the resolutions
on the package.json
"package": "portal:/absolute/path/to/my/package"
For anyone struggling
yarn 3
on a private packageon your package
yarn link
Then on the repo you want the linked package
# p is for private package yarn link -p ~/path/to/my/package
This will add this line to the
resolutions
on thepackage.json
"package": "portal:/absolute/path/to/my/package"
im getting
$ yarn link Unknown Syntax Error: Not enough positional arguments.
$ yarn link [-A,--all] [-p,--private] [-r,--relative]
any help
For anyone struggling
yarn 3
on a private packageon your package
yarn link
Then on the repo you want the linked package
# p is for private package yarn link -p ~/path/to/my/package
This will add this line to the
resolutions
on thepackage.json
"package": "portal:/absolute/path/to/my/package"
This very much didn't work for me. The yarn link -p
command tried somehow to link the repo I was in (where I wanted to use my linked package)
➜ api_v5 ✗ yarn link
yarn link v1.22.19
success Registered "@myorg/api-v5-typescript-schema".
info You can now run `yarn link "@ myorg/api-v5-typescript-schema"` in the projects where you want to use this package and it will be used instead.
✨ Done in 0.06s.
➜ api_v5 ✗ cd ../storefront-remix
➜ storefront-remix git:(develop) ✗ yarn link -p ~/dev/myorg/myorg-api/typescript-schemas/api_v5
yarn link v1.22.19
success Registered "platform".
info You can now run `yarn link "platform"` in the projects where you want to use this package and it will be used instead.
✨ Done in 0.04s.
Is anyone still struggling with this? I have a very simple setup with two local packages one linked and the other should install the first one from local but I keep getting 404 errors, I tried removing and adding again but that did nothing
Just been bitten by this as well, and this issue helped tremendously so thank you 🙇🏽
Using yarn 1.22.19 and my ~/.config
folder was a symlink, so this seems to be a good root cause.
For anyone struggling
yarn 3
on a private package on your packageyarn link
Then on the repo you want the linked package
# p is for private package yarn link -p ~/path/to/my/package
This will add this line to the
resolutions
on thepackage.json
"package": "portal:/absolute/path/to/my/package"
im getting
$ yarn link Unknown Syntax Error: Not enough positional arguments.
$ yarn link [-A,--all] [-p,--private] [-r,--relative]
any help
Hi, not sure if you still need help. But if you don't this may also help other people.
I've been struggling to link my local project all day and finally come to the conclusion that yarn link is aimless for Yarn 3+ at least. This stack overflow answer helped, you need to use the portal protocol to obtain the package which is the symlink. Okay, cool, but how do we use it?
The only solution that worked for me is to:
yarn add package-name@portal:<path to package name>
.
I've tested this over and over again, and doing a yarn link on the package simply doesn't work. You need to add the symlink via a portal using the above yarn add
.
If you somehow figure out that yarn link does indeed work for you (and you're using Yarn 3+) you cannot set a link on the current package but rather in the place you require it, you need to link it from there. https://yarnpkg.com/cli/link
Edit: For further help to those still a little confused. Ensure the package you want to import has been built. If you're using a front-end tool like Vite, you can use the command yarn build --watch
to continuously build the package on every save and the package using the imported package will update.
Hope this helps all :)
I am hitting this with [email protected]
.
When looking in my .config/yarn/link
folder, the symlink was there but was invalid. I deleted it and manually created the symlink myself, and now I can successfully link this package into another package that wants to use it.
my .config folder is not a symlink.
Manually creating the symlink is tedious, but it does accomplish the task so I'll take it.
I am hitting this with
[email protected]
.When looking in my
.config/yarn/link
folder, the symlink was there but was invalid. I deleted it and manually created the symlink myself, and now I can successfully link this package into another package that wants to use it.my .config folder is not a symlink.
Manually creating the symlink is tedious, but it does accomplish the task so I'll take it.
Where's the .config/yarn/link
folder located?
@alexander01202
I am hitting this with
[email protected]
. When looking in my.config/yarn/link
folder, the symlink was there but was invalid. I deleted it and manually created the symlink myself, and now I can successfully link this package into another package that wants to use it. my .config folder is not a symlink. Manually creating the symlink is tedious, but it does accomplish the task so I'll take it.Where's the
.config/yarn/link
folder located?
Your home directory:
$ echo $HOME
It seems for yarn 4 the way link works has changed from older versions. I was confused, but I tried the method from the yarn 4 docs and it seems to work.
Yarn classic
- Register your package with
yarn link
form the package directory - Link to the registered package by running
yarn link "package name"
from the consuming app directory
Yarn 4
- Link to your package by running
yarn link 'relative/path/to/your/package'
from the consuming app directory
@p-sebastian Running yarn link -p ~/path/to/my/package
works, but there's a breaking issue with this approach. Since we're using multiple machines with these installs, we don't need yarn to insert paths to our individual home directories in package.json. Otherwise, those changes constantly get synched via git and have to be changed every time we do a git pull
.
Is there a way to link to global packages without having to insert your home directory into the package.json resolutions? We're trying to globally link to some pretty large libraries like Font Awesome, so we can package them into custom fonts per site.
This used to be possible with npm global installs, but newer versions of yarn seem to be deprecating all this.
yarn 4+
couldn't use yarn link
in projectA to be able to link it in projectB using yarn link projectA
or a relative path yarn link rel/projectA
projectA is using yarn 4+ but projectB is using yarn classic
EDIT: upgrading yarn in projectB (yarn set version berry
) solved my issue
now using yarn link rel/path/to/projectA
inside projectB works fine