A
arktypeā€¢2mo ago
PIat

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:
Tried to initialize an $ark registry but one already existed. This probably means you are either depending on multiple versions of an arktype package, or importing the same package from both ESM and CJS.
Review package.json versions across your repo to ensure consistency.
Tried to initialize an $ark registry but one already existed. This probably means you are either depending on multiple versions of an arktype package, or importing the same package from both ESM and CJS.
Review package.json versions across your repo to ensure consistency.
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
Dimava
Dimavaā€¢2mo ago
Is AT a peer dep? Is lockfile AT dep the same?
PIat
PIatā€¢2mo ago
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
ssalbdivad
ssalbdivadā€¢5w ago
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
PIat
PIatā€¢5w ago
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.
Dimava
Dimavaā€¢5w ago
šŸ¤” Does error message contain a link to arktype.io which contains a link to github discussion about how to fix this problem?
ssalbdivad
ssalbdivadā€¢5w ago
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
PIat
PIatā€¢5w ago
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
ssalbdivad
ssalbdivadā€¢5w ago
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?
PIat
PIatā€¢5w ago
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
ssalbdivad
ssalbdivadā€¢5w ago
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
PIat
PIatā€¢5w ago
Let's try! This was thrown:
throw new ctor(message);
ParseError: 'parse.number' is unresolvable
at throwError (.../node_modules/.pnpm/@ark+util@0.2.1/node_modules/@ark/util/out/errors.js:5:11)
at throwParseError
throw new ctor(message);
ParseError: 'parse.number' is unresolvable
at throwError (.../node_modules/.pnpm/@ark+util@0.2.1/node_modules/@ark/util/out/errors.js:5:11)
at throwParseError
ssalbdivad
ssalbdivadā€¢5w ago
šŸ˜­ How would it get worse
PIat
PIatā€¢5w ago
Version 2.0.0-beta.5
ssalbdivad
ssalbdivadā€¢5w ago
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?
PIat
PIatā€¢5w ago
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
Want results from more Discord servers?
Add your server