yalc
yalc copied to clipboard
Does Yalc resolve dependencies as if I npm installed the local module?
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)?
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.
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
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
?
The following should be added to the docs:
If your project is not using Yarn, you must run
npm install
(or similar) afteryalc 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.
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
I assume the intention was for users to run
yarn
(or similar) afteryalc link
to ensure the dependencies are installed. Maybe there's a good argument for copyingnode_modules
into.yalc/{name}/node_modules
duringyalc 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.
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)
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!