yalc icon indicating copy to clipboard operation
yalc copied to clipboard

Does Yalc resolve dependencies as if I npm installed the local module?

Open naddison opened this issue 6 years ago • 10 comments

Let's say I have two packages A and B. B depends on A. I use yalc to add A to B, will yalc resolve A's dependencies into B's node_modules folder (as if I npm installed A)?

naddison avatar Dec 02 '18 21:12 naddison

Let's say I have two packages A and B. B depends on A. I use yalc to add A to B, will yalc resolve A's dependencies into B's node_modules folder (as if I npm installed A)?

You mean after you installed then B somewhere? if your B package will contain .yalc/A folder inside then yes.

wclr avatar Dec 03 '18 11:12 wclr

This question may have been misread. From a look at the code, it seems that the dependencies of package "A" are not resolvable when a consuming package "B" uses yalc link.

For example, if both of these are true:

  • package "A" depends on package "C" (via npm install)
  • package "B" depends on package "A" (via yalc link)

..then this is also true:

  • package "C" is missing from $B/.yalc/$A/node_modules

aleclarson avatar Jan 02 '19 14:01 aleclarson

I assume the intention was for users to run yarn (or similar) after yalc link to ensure the dependencies are installed. Maybe there's a good argument for copying node_modules into .yalc/{name}/node_modules during yalc link?

aleclarson avatar Jan 02 '19 14:01 aleclarson

The following should be added to the docs:

If your project is not using Yarn, you must run npm install (or similar) after yalc add in order to install the added package's dependencies.

Then, we should change yalc link to run npm install (or yarn if --yarn was used) inside the .yalc/{name} directory. I was considering just copying node_modules during yalc publish, but I decided it's better to mimic a "normal install" as much as possible.

I'll be working on a PR sometime soon, so LMK what you think @whitecolor.

aleclarson avatar Jan 02 '19 15:01 aleclarson

Hmm, actually, it might be best to run npm install (or yarn if yarn.lock exists) in ~/.yalc during yalc publish or yalc push.

PS: I'm curious, why does yalc add need to copy the .yalc/{name} directory into node_modules? Why not use a symlink like yalc link does? Then, the only difference between add and link would be that add mutates the package.json of the consuming package.

aleclarson avatar Jan 02 '19 16:01 aleclarson

@aleclarson

I assume the intention was for users to run yarn (or similar) after yalc link to ensure the dependencies are installed. Maybe there's a good argument for copying node_modules into .yalc/{name}/node_modules during yalc link?

I agree, this is the workflow I ended up using. I'm not a fan of installing the node_modules into the yalc directory though. The main reason I started using yalc is to solve an issue where I'd have duplicate versions of React in my node_modules in my linked environment but not my production environment. I've proposed instead that it runt's yarn link or npm install in my issue: #81.

luk707 avatar Apr 18 '19 08:04 luk707

I am hitting this issue with Next.js + Storybook, must admit it's confusing at first. I'd rather had yalc behaving exactly like an NPM registry, but local. The problem is that when I run the npm install, it also kinda defeats the purpose of Yalc. For a precise example, Next.js will use Webpack 4 internally. But some app may use Webpack 5. If I don't do the npm install, just yalc link, it will use my app Webpack 5 install as expected (this is why I am using Yalc in the first place, Yarn link won't allow that). But I have missing packages then. If I do the npm install, back to square one....

(non minimal) reproduction here: https://github.com/lbke/next-plugin-storybook-demo, if you don't npm install you have errors with either chalk or jest-worker, because it is not installed in the linked next.js deps.

I am not knowledgeable enough to fully grasp what happens, but it doesn't seem to behave like an npm install would do.

Note I am using yarn, and yalc link (but not yalc add I am not fond of the file:// dependency)

eric-burel avatar May 07 '21 12:05 eric-burel

Was this issue ever resolved? I'm having a very similar issue. When I run yalc link A in package B, I don't see C appear anywhere. Not in B/node_modules, not in B/.yalc/A, and not in ~/.yalc/packages/A. At that point I run yarn install and nothing happens, it just says "Already up-to-date". Regardless of the ultimate resolution of this issue, I would love to understand better how this is working so I can at least get it working. Thank you for your help and this great package!

danny-does-stuff avatar May 25 '23 16:05 danny-does-stuff