Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn link doesn't work #1297

Open
RusPosevkin opened this issue Oct 20, 2016 · 42 comments

Comments

Projects
None yet
@RusPosevkin
Copy link

commented Oct 20, 2016

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
@RusPosevkin

This comment has been minimized.

Copy link
Author

commented Oct 20, 2016

Probably, there is a bug when linked package name include the hyphen. The same problem may be in #1161.

@ssteinerx

This comment has been minimized.

Copy link

commented Oct 24, 2016

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.

@mattmccray mattmccray referenced this issue Oct 30, 2016

Closed

yarn link #60

@jampy

This comment has been minimized.

Copy link

commented Nov 22, 2016

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:

  • building inside a Docker container, as "root", within a VM in Windows
  • I have three packages locally under /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.
  • The main application under /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.
  • Since the tonidb* packages are unreleased to NPM yet, I've added them to the package.json files simply like "tonidb": "*".
  • Yarn version is v0.17.8.

I have no idea why the link works for the dependencies themselves but not for the main application.

@jampy

This comment has been minimized.

Copy link

commented Dec 16, 2016

Hmmm, anybody found a workaround?

Would like to use Yarn, but this is a major blocker :(

@cdomigan

This comment has been minimized.

Copy link

commented Feb 25, 2017

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?

@RusPosevkin

This comment has been minimized.

Copy link
Author

commented Mar 27, 2017

Hey guys, let's try to use symbolic linking instead

  $> ln -nsf ../foo node_modules/foo

It can be used into package.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:

  $> yarn run setup
@StarpTech

This comment has been minimized.

Copy link

commented Apr 26, 2017

Run into the same issue. After linking and install the package I got:

yarn
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.
@bestander

This comment has been minimized.

Copy link
Member

commented Apr 28, 2017

We are going to revamp link: feature soon, see yarnpkg/rfcs#34

@voxsim

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2017

Ok I will wait you guys, if you need some help let me know :)

@gsklee

This comment has been minimized.

Copy link
Contributor

commented Jun 21, 2017

@RusPosevkin could you confirm that if this issue has been resolved in v0.26 prerelease?

@fugufish

This comment has been minimized.

Copy link

commented Jun 28, 2017

it does not seem to to work on latest prerelease

@alexre0

This comment has been minimized.

Copy link

commented Jun 30, 2017

+1

@bestander

This comment has been minimized.

Copy link
Member

commented Jun 30, 2017

I could not reproduce on latest yarn@0.27.3.
Closing.

@fugufish and @alexre0, please provide a test script how I can reproduce it not working.
Better open a new issue with the steps.

@bestander bestander closed this Jun 30, 2017

@fugufish

This comment has been minimized.

Copy link

commented Jul 1, 2017

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

@bestander

This comment has been minimized.

Copy link
Member

commented Jul 1, 2017

first time you need to call yarn link without package name.

@fugufish

This comment has been minimized.

Copy link

commented Jul 1, 2017

either way it doesn't work.

@cloakedninjas

This comment has been minimized.

Copy link

commented Jul 7, 2017

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'
@bestander

This comment has been minimized.

Copy link
Member

commented Jul 7, 2017

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.

@bestander

This comment has been minimized.

Copy link
Member

commented Jul 7, 2017

@cloakedninjas, yarn would not run install on linked project, this is expected behavior.
Workspaces feature should address this, it is still experimental

@cobyism

This comment has been minimized.

Copy link

commented Oct 3, 2017

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?

@bestander

This comment has been minimized.

Copy link
Member

commented Oct 4, 2017

Can you do yarn link some-module without the double quotes?

@cobyism

This comment has been minimized.

Copy link

commented Oct 4, 2017

Can you do yarn link some-module without the double quotes?

Exactly the same behaviour, regardless of presence/absence or quote type (' vs. ").

@bestander

This comment has been minimized.

Copy link
Member

commented Oct 4, 2017

Oh wait, your yarn is version 0.17.8, that is very old, can you upgrade to latest?
https://yarnpkg.com/en/docs/install

@p12y

This comment has been minimized.

Copy link

commented Oct 12, 2017

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.

@lgirma

This comment has been minimized.

Copy link

commented Nov 4, 2017

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.

@HazAT

This comment has been minimized.

Copy link

commented Dec 5, 2017

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".
@natew

This comment has been minimized.

Copy link

commented Feb 20, 2018

I get this with scoped packages, not sure if that's different.

@Abdisalan

This comment has been minimized.

Copy link

commented Apr 2, 2018

Running into this issue as well, the same way @cobyism and @lgirma described

@JimmyCDChen

This comment has been minimized.

Copy link

commented Apr 13, 2018

Seeing the same issue with yarn link. In the same boat with @Abdisalan

@sandalsoft

This comment has been minimized.

Copy link

commented Apr 21, 2018

I was getting this error:
Error: Cannot find module '<package name>'

What worked for me was:

  1. run yarn link in the <package name> module directory.
  2. yarn build the <package name> module.
  3. run yarn link <package name> in the app directory I'm trying to include <package name> in.
@travomic

This comment has been minimized.

Copy link

commented May 23, 2018

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

screen shot 2018-05-23 at 10 56 11 am

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.

@wayou

This comment has been minimized.

Copy link

commented Sep 8, 2018

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.

@ConAntonakos

This comment has been minimized.

Copy link
Contributor

commented Dec 11, 2018

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.

@nemoDreamer

This comment has been minimized.

Copy link

commented Jan 22, 2019

@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 in
  • yarn link "blahblah" just like the CLI says:
    • error No registered package found called "@myscope/blahblah".
      
  • maybe yarn install?
    • The target of linked package "@myscope/blahblah" is missing. Removing link.
      
  • ls -l ~/.config/yarn/link/@myscope/
    • nothing left?!

I have a "main" entry, I have some "bin" entries, I've tried making it an un-scoped package, etc...

@bestander

This comment has been minimized.

Copy link
Member

commented Feb 12, 2019

@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.

@apfelfabrik

This comment has been minimized.

Copy link

commented Feb 13, 2019

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: #7028

@p3x-robot

This comment has been minimized.

Copy link

commented Feb 20, 2019

yeah, it is not working with scoped packages for sure.

@stephenhurleyjpl

This comment has been minimized.

Copy link

commented Apr 18, 2019

@apfelfabrik That PR looks very promising, and is I think exactly what I need! Do you know what's holding up the PR?

@rodrigoyoshida

This comment has been minimized.

Copy link

commented May 24, 2019

Same here, struggling for hours to find out a way to make it work.

@tamzinblake

This comment has been minimized.

Copy link

commented Jun 18, 2019

Still encountering the same problem now. Has anyone figured out a fix for this (for scoped packages) yet?

@stephenhurleyjpl

This comment has been minimized.

Copy link

commented Jun 18, 2019

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.

@skwny

This comment has been minimized.

Copy link

commented Jun 18, 2019

Still encountering the same problem now. Has anyone figured out a fix for this (for scoped packages) yet?

Switched back to npm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.