yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Yarn link doesn't work

Open RusPosevkin opened this issue 9 years ago • 81 comments

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 avatar Oct 20 '16 10:10 RusPosevkin

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

RusPosevkin avatar Oct 20 '16 11:10 RusPosevkin

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.

ssteinerx avatar Oct 24 '16 02:10 ssteinerx

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 avatar Nov 22 '16 15:11 jampy

Hmmm, anybody found a workaround?

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

jampy avatar Dec 16 '16 12:12 jampy

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?

cdomigan avatar Feb 25 '17 00:02 cdomigan

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

RusPosevkin avatar Mar 27 '17 13:03 RusPosevkin

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.

StarpTech avatar Apr 26 '17 10:04 StarpTech

We are going to revamp link: feature soon, see https://github.com/yarnpkg/rfcs/pull/34

bestander avatar Apr 28 '17 15:04 bestander

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

voxsim avatar Apr 30 '17 09:04 voxsim

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

gsklee avatar Jun 21 '17 06:06 gsklee

it does not seem to to work on latest prerelease

fugufish avatar Jun 28 '17 17:06 fugufish

+1

alexre0 avatar Jun 30 '17 17:06 alexre0

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.

bestander avatar Jun 30 '17 19:06 bestander

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

fugufish avatar Jul 01 '17 05:07 fugufish

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

bestander avatar Jul 01 '17 06:07 bestander

either way it doesn't work.

fugufish avatar Jul 01 '17 15:07 fugufish

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'

cloakedninjas avatar Jul 07 '17 10:07 cloakedninjas

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 avatar Jul 07 '17 18:07 bestander

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

bestander avatar Jul 07 '17 18:07 bestander

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?

cobyism avatar Oct 03 '17 14:10 cobyism

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

bestander avatar Oct 04 '17 04:10 bestander

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

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

cobyism avatar Oct 04 '17 08:10 cobyism

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

bestander avatar Oct 04 '17 15:10 bestander

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.

p12y avatar Oct 12 '17 21:10 p12y

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.

lgirma avatar Nov 04 '17 07:11 lgirma

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

HazAT avatar Dec 05 '17 16:12 HazAT

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

natew avatar Feb 20 '18 20:02 natew

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

Abdisalan avatar Apr 02 '18 21:04 Abdisalan

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

JimmyCDChen avatar Apr 13 '18 22:04 JimmyCDChen

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.

sandalsoft avatar Apr 21 '18 04:04 sandalsoft