Tried to initialize an $ark registry in a monorepo
Hello! In a
pnpm
workspace, I have 2 packages depending on arktype
. This means that each package depends on arktype
separately. However, when I import them into a central vite
project, I get the error:
Both packages are compiled to ESM, and the arktype
version is identical, so the issue must be in them clashing inside of the vite
project. What would be a good way to avoid this error?126 Replies
Is AT a peer dep?
Is lockfile AT dep the same?
It is a peer dep, since the package is installed as a dependency of an app, and
arktype
is the dependency of the package
The issue was in me bundling all dependencies into the build by accident. So each package was running globalThis.$ark = registry;
independently
Also it was important to add public-hoist-pattern[]=*arktype*
to .npmrc
Which version of ArkType is this? Does it crash or is it this just logged as a warning.
Based on my discussions with @Andarist, I'm not sure there's anything I can do internally to avoid this, hopefully getting the error as you did was helpful in this case? I do think having an option to disable the warning in situations where it's inevitable but you know it is safe would be good
Hello @ssalbdivad! It's the version
2.0.0-dev.26
. It crashed the app completely. I don't think it's a bad thing, the error message was very useful, and I understood in a bit what I needed to do. It's actually a similar issue you run into with for example Prisma
when using pnpm
workspaces.
You need to put public-hoist-pattern[]=*arktype*
into .npmrc
to make sure that the package isn't installed and ran from in package or its dependents separately, but is only installed in a single location - at the root of the workspace.š¤
Does error message contain a link to arktype.io which contains a link to github discussion about how to fix this problem?
Hmm, but ideally even if it's not hoisted pnpm should create symlinks that resolve to the same files. Does it load twice in that case?
No, but the error especially in more recent versions is extremely specific there is nothing else generalizable I could add
Since without hoisting it it gets installed into the
node_modules
folders separately, I'd expect arktype
to load twice if the app depends on two modules, which both depend on arktype
Yeah in general the idea of pnpm is that it dedupes dependencies, but I guess I'm only aware of how that works transitively. I'm not 100% on how it works with symlinks directly in each package's node_modules, although I'd expect it would also be the same?
I also have a very rough idea of it, I don't want to confuse you with disinformation
However, each time I need to make sure a package is instantiated only once, I hoist it
Interested to know what behavior you get when you update since I made some changes around this. I'd guess if you turned off hoisting you'd just get a console warning
Let's try!
This was thrown:
š
How would it get worse
Version
2.0.0-beta.5
Maybe I was right to just try and throw š¤£
It does seem related to the registry issue
You don't get a warning before that though?
Sorry it took so long, I accidentally did
i -r
instead of up -r
and got it installed in 21 modules š
I didn't
I'll try with hoisting now