Do you want to request a _feature_ or report a _bug_?
Bug.
What is the current behavior?
foo@bar:~/code/lpserver/frontend/addons/lp-base$ yarn link
yarn link v0.16.1
success Registered "lp-base".
info You can now run `yarn link "lp-base"` in the projects where you want to use this module and it will be used instead.
Done in 0.05s.
foo@bar:~/code/lpserver/frontend/addons/lp-base$ cd ../../apps/partner/
foo@bar:~/code/lpserver/frontend/apps/partner$ yarn link lp-base
yarn link v0.16.1
success Registered "lp-base".
Done in 0.05s.
foo@bar:~/code/lpserver/frontend/apps/partner$ yarn
yarn install v0.16.1
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find package "lp-base" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
If the current behavior is a bug, please provide the steps to reproduce.
See above.
What is the expected behavior?
foo@bar:~/code/lpserver/frontend/addons/lp-base$ yarn link
yarn link v0.16.1
success Registered "lp-base".
info You can now run `yarn link "lp-base"` in the projects where you want to use this module and it will be used instead.
Done in 0.05s.
foo@bar:~/code/lpserver/frontend/addons/lp-base$ cd ../../apps/partner/
foo@bar:~/code/lpserver/frontend/apps/partner$ yarn link lp-base
yarn link v0.16.1
success Registered "lp-base".
Done in 0.05s.
foo@bar:~/code/lpserver/frontend/apps/partner$ yarn
yarn install v0.16.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 0.46s.
Please mention your node.js, yarn and operating system version.
node 6.4.0
yarn 0.16.1
Ubuntu 16.04 LTS
Probably, there is a bug when linked package name include the hyphen. The same problem may be in #1161.
Same problem with package with no hyphen in name; it still looks for package in on the "npm" registry.
Dead in the water without this working on my current project.
Any news on this?
I think I'm having the same issue (at least the result is the same).
If it helps, some details regarding my situation:
/src-protected/tonidb/packages
named tonidb
, tonidb-odm
and tonidb-server
. The last two depend on tonidb
and thus are linked using yarn link tonidb
. This works as the integrated tests succeed (yarn run test
), so linking somehow works./src-protected/winfarmer-xt/src
is linked to the three packages just mentioned, but fails with errors like Couldn't find package "tonidb" on the "npm" registry.
. The package name in the error message randomly switches between one of the three package names - I guess that's simple because of the parallel install.tonidb*
packages are unreleased to NPM yet, I've added them to the package.json
files simply like "tonidb": "*"
.I have no idea why the link works for the dependencies themselves but not for the main application.
Hmmm, anybody found a workaround?
Would like to use Yarn, but this is a major blocker :(
Yarn link seems completely broken? Would be great to get an update from the devs on this. Is anybody having luck using link at all?
Hey guys, let's try to use symbolic linking instead
$> ln -nsf ../foo node_modules/foo
```
It can be used into package.json:
``` json
"scripts": {
"link": "(mkdir node_modules || true) && ln -nsf ../foo node_modules/foo && ln -nsf ../bar node_modules/bar",
"setup": "yarn run link && yarn"
},
Just run setup task:
bash
$> yarn run setup
Run into the same issue. After linking and install the package I got:
yarn install v0.23.2
[1/4] Resolving packages...
error Received malformed response from registry for "local-test". The registry may be down.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
We are going to revamp link: feature soon, see https://github.com/yarnpkg/rfcs/pull/34
Ok I will wait you guys, if you need some help let me know :)
@RusPosevkin could you confirm that if this issue has been resolved in v0.26 prerelease?
it does not seem to to work on latest prerelease
+1
I could not reproduce on latest [email protected].
Closing.
@fugufish and @alexre0, please provide a test script how I can reproduce it not working.
Better open a new issue with the steps.
create a brand new package that is not registered on npm, use yarn link <package-name>
create project that references that package and version, use yarn link <package-name>
package correctly shows up in node_modules
call yarn install
an error will be thrown saying the package does not exist on the npm registry
first time you need to call yarn link
without package name.
either way it doesn't work.
This is borked for me too - only when my dependency is installed locally can I get things to work, otherwise:
var gulp = require('gulp');
Error: Cannot find module 'gulp'
I think we are talking about different issues here.
@fugufish, do I understand it right that you yarn link project-b
and also have a project-b
in package.json?
I think Yarn may not work with linking and depending at the same time, it's probably a separate bug.
For a workaround you can try "project-b": "link:./path/to/project-b"
, it will create a symlink when you run yarn install
.
@cloakedninjas, yarn would not run install on linked project, this is expected behavior.
Workspaces feature should address this, it is still experimental
Pretty sure there’s still something messed up with this command. Here’s what I’m running into:
$ cd ~/code/some-module
$ yarn link
yarn link v0.17.8
success Registered "some-module".
info You can now run `yarn link "some-module"` in the projects where you want to use this module and it will be used instead.
✨ Done in 0.07s.
$ cd ../main-project
$ yarn link "some-module"
yarn link v0.17.8
error No registered module found called "some-module".
info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.
What am I missing?
Can you do yarn link some-module
without the double quotes?
Can you do yarn link some-module without the double quotes?
Exactly the same behaviour, regardless of presence/absence or quote type ('
vs. "
).
Oh wait, your yarn is version 0.17.8, that is very old, can you upgrade to latest?
https://yarnpkg.com/en/docs/install
I'm getting the same thing as @cobyism. I've got the latest version of yarn. Create a link in node_modules, navigate to app folder, yarn link [package_name], package disappears from node_modules. The only way I can even fire up a server afterward is by reinstalling the package.
Same issues here.
Using yarn version 1.2.1
, node version 8.4.0
Running the commands yarn link
and yarn link some-module
seems to work fine (at least yarn reports they went well), until I do a build and then get Cannot find module some-module
error.
I am also running in this issue.
So the behavior I would expect is that yarn install
skips the modules I already linked before
e.g.:
yarn link # in packages/local-test
# somewhere else
yarn link local-test
yarn install
# no longer tries to install local-test from registry
# even though it's in my package.json as a dependency
Currently, I am getting:
yarn install v1.3.2
[1/5] Validating package.json...
[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/local-test: Not found".
I get this with scoped packages, not sure if that's different.
Running into this issue as well, the same way @cobyism and @lgirma described
Seeing the same issue with yarn link. In the same boat with @Abdisalan
I was getting this error:
Error: Cannot find module '<package name>'
What worked for me was:
yarn link
in the \yarn build
the \yarn link <package name>
in the app directory I'm trying to include \Here's something that threw me off: The output after linking a module, puts the name of the package in double-quotes (highlighted below) ... when pasting that command, it cant find the linked module unless you remove the double-quotes. e.g: yarn link @travomic/svg-tagged-template
I poked around in the internals of yarn for a little bit and found linkRegisteredMessage
gets supplied the package.json config values via the readRootManifest
method in the config module... But kinda stopped digging. Perhaps someone with more gumption than I have can make a PR to either handle the link argument with and without the double-quoted value. Or, simply fix the success message after linking to not show the quotes.
For others who has the same problem, I think this may help:
make sure the linked module's main file (the main
section in package.json
) exists, maybe you wanna run build before link it so it can be accessed.
I don't understand what I'm doing wrong. I keep getting the following error:
error No registered package found called "<package_name>"
After banging my head against this for a while, I finally attempted sudo yarn link <package_name>
, and that worked! I had to sudo yarn
, though, afterwards, which doesn't feel right.
@bestander don't you think this issue was prematurely closed? It's obviously not resolved, as there are now multiple duplicate issues complaining about link
being broken.
Many repro steps outline the exact same behavior:
yarn link
in the "@myscope/blahblah" package to be linked
success Registered "@myscope/blahblah".
info You can now run `yarn link "@myscope/blahblah"` in the projects where you want to use this package and it will be used instead.
ls -l ~/.config/yarn/link/@myscope/
blahblah -> ../../../../Development/myscope/packages/blahblah
cd
to package you want the link to be used inyarn link "blahblah"
just like the CLI says:
error No registered package found called "@myscope/blahblah".
yarn install
?
The target of linked package "@myscope/blahblah" is missing. Removing link.
ls -l ~/.config/yarn/link/@myscope/
I have a "main"
entry, I have some "bin"
entries, I've tried making it an un-scoped package, etc...
@nemoDreamer, thanks for bringing it to my attention.
Looks like the linked module can't be found in some cases and this is common enough to cause so many upvotes.
I would dig into the JS code where "error No registered package found called "@myscope/blahblah"." is generated.
I can open the bug but help from community to find the issue and provide test cases is needed.
I ran into the same issue:
➜ dep-a $ yarn link
yarn link v1.15.0-0
success Registered "@company/dep-a".
info You can now run `yarn link "@company/dep-a"` in the projects where you want to use this package and it will be used instead.
✨ Done in 0.34s.
➜ dep-a $ cd ../..
➜ parent $ yarn link "@company/dep-a"
yarn link v1.15.0-0
error No registered package found called "@company/dep-a".
info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.
The reason this failed for me is that ~/.config
was a symlink itself, so that when creating symlinks in ~/.config/yarn/link
without resolving the real path first, the resulting symlinks for the linked packages are broken.
Quick fix for anyone affected could be to identify symlinks upwards of yarn's link folder and remove them. Proper fix should be in this PR: https://github.com/yarnpkg/yarn/pull/7028
yeah, it is not working with scoped packages for sure.
@apfelfabrik That PR looks very promising, and is I think exactly what I need! Do you know what's holding up the PR?
Same here, struggling for hours to find out a way to make it work.
Still encountering the same problem now. Has anyone figured out a fix for this (for scoped packages) yet?
My specific problem was that when I ran yarn link
in my dep
repo, it created a symbolic link at /home/steve/.config/yarn/link/dep
pointing to /home/steve/projects/dep
(using the absolute path like you see here). However, my home
folder is a symbolic link within the /
folder and yarn seems to have trouble with any part of the whole path being a symbolic link, just like apfelfabrik mentioned.
I manually changed the /home/steve/.config/yarn/link/dep
to instead point to ../../../projects/dep
(rm dep && ln -s dep ../../../projects/dep
), and this fixed the problem for me.
Still awaiting the PR so that yarn automatically fixes it. The PR is a one-line change, so I'm not sure why it's being held up.
Still encountering the same problem now. Has anyone figured out a fix for this (for scoped packages) yet?
Switched back to npm :)
Please fix.
@apfelfabrik hit the nail on the head!
The reason this failed for me is that ~/.config was a symlink itself, so that when creating symlinks in ~/.config/yarn/link without resolving the real path first, the resulting symlinks for the linked packages are broken.
Quick fix for anyone affected could be to identify symlinks upwards of yarn's link folder and remove them. Proper fix should be in this PR: #7028
My ~/.config
was a symlink created by my dotfiles
script...
When I ran link with an explicit link-folder that _wasn't_ a symlink or a child of a symlink, it worked!
yarn link --link-folder ~/.links
then
yarn link --link-folder ~/.links @my/package
🎉
@nemoDreamer thanks for the solution, my ~/.config/
was also a symlink.
I just directly setup:
yarn link --link-folder ~/src/dotfiles/config/yarn/link/
Can't get yarn link
to work with github actions. Need this so my tests and the build see the 'bin' cli tool.
Perhaps what's even more odd is that the tests themselves execute yarn link
within a temp folder and unless you call npm link
these seem to fail.
Assuming you have a project in the folder "project-a" and would like to reference it from another "project-b", the following worked for me:
cd ~/project-a
yarn link
You will get the following message
yarn link vx.xx.x
success Registered "project-a".
Then do the following...
cd ~/project-b
yarn link project-a
You will get the following message
~/project-b/node_modules/@competec-ch/b2c-event-bus -> [full-path]/project-a
yarn add [full-path]/project-a
After which you can require('project-a')
or import from 'project-a'
.
Pretty sure there’s still something messed up with this command. Here’s what I’m running into:
$ cd ~/code/some-module $ yarn link yarn link v0.17.8 success Registered "some-module". info You can now run `yarn link "some-module"` in the projects where you want to use this module and it will be used instead. ✨ Done in 0.07s. $ cd ../main-project $ yarn link "some-module" yarn link v0.17.8 error No registered module found called "some-module". info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.
What am I missing?
Try to consider the package.json project name
I just ran into the same issues as https://github.com/yarnpkg/yarn/issues/1297#issuecomment-456576816 with Yarn 1.22.4 on macOS. yarn link
does create the symlink, but the target is a really long relative path that for some reason both the operating system (via ls
) and Node.js think the symlink is broken.
It's not a permission issue. Maybe there are too many parent directory references and something gets confused? FWIW, I did poke around the Yarn source and found where the symlink was being created, but it wasn't clear how the target was being resolved such that it had so many parent directory references. Perhaps passing a path.resolve()
around the target when calling fs.symlink()
would solve it?
As a super hacky workaround, I wrote some code that walks the Yarn links directory and if the file/symlink does not exist (e.g. fs.existsSync()
returns false
), but it's a symlink (e.g. fs.lstatSync().isSymbolicLink()
returns true
), then I unlink the borked symlink and create a new symlink pointing to path.resolve(fs.readlinkSync())
.
Struggled w/ this for a few minutes. Missed the double quotes for the package name. Seems really unnecessary to need them in general...
For me following worked-
In module-1 -
$ yarn link
then in module-2 -
$ yarn link "module-1"
$ yarn add module-1@link:1.0.0
Last command will add dependency to package.json of module-2, with a link keyword telling that it is a linked module. After doing that if you do
$ yarn
it will be able to resolve the dependency.
In my case I thought it's not working, but then realized it was actually working, but it's just not working when my app is run inside of a docker container. (Docker containers do not include files from symlinks that lead to files outside of the docker container directory.) More details here: https://github.com/npm/npm/issues/14325 .
Might be helpful to some folks.
Most helpful comment
Same issues here.
Using yarn version
1.2.1
, node version8.4.0
Running the commands
yarn link
andyarn link some-module
seems to work fine (at least yarn reports they went well), until I do a build and then getCannot find module some-module
error.