Closed Metehan-Altuntekin closed 10 months ago
The package.json
of the npm library svelte-jsoneditor
does contain ajv
in the dependencies. I do not understand why any client would not install the dependency? Can you provide a minimal example demonstrating the issue?
See package.json: https://unpkg.com/svelte-jsoneditor@0.17.3/package.json
Yeah, that is really weird isn't it? I think it's related to pnpm
more than svelte-jsoneditor
itself. Even when it is not a monorepo, ajv
is not installed properly when I use pnpm
but npm
or yarn
installs just right.
Example of installing with pnpm
in a non monorepo poject:
Example of installing with npm
in a non monorepo project:
Found more details, apparently pnpm
installs package dependencies into node_modules/.pnpm/
directory like so:
The non-monorepo pnpm
installed repository works just fine. But the error occurs in the monorepo one even though it installs ajv
to that directory too:
But in a monorepo, ajv
is installed in the node_modules/.pnpm/
directory of the repo root. Not in the workspace's node_modules/.pnpm
of the nested workspace. This behaviour is not exceptional for ajv
or svelte-jsoneditor
though, it appears to be the way of doing things for pnpm
.
Maybe this topic is relevant: https://stackoverflow.com/questions/70597494/pnpm-does-not-resolve-dependencies
Thanks @josdejong, it helped with the error but the trade-off is that it allows to import non declared dependencies and that is not ideal. I found that enabling that only for ajv
with public-hoist-pattern[]=ajv
also works and it's less dangerous. Still, it will not prevent importing ajv
in workspaces that doesn't have it as a dependency so not finding it ideal.
I think the issue may be more closely related to Vite, since this error occurs within a Vite Dependency Pre-Bundling.
I have checked the same file at 2 different cases and there are differences in way it imports ajv
When I install with pnpm i
:
When I install with pnpm i --shamefully-hoist=true
:
Isn't it interesting that about 300 of results just disappear?
I'm not sure how I can help. Is there anything in svelte-jsoneditor
that we can change to improve this? Or do we have to report something at ajv
or pnpm or vite?
I'm not sure either. My best guess is it's Vite but I can't speak for sure without examining the code
I think the next steps are:
ajv
and vite
, or that it has to do with how svelte-jsoneditor
uses ajv
(i.e. rule out as much factors as possible)Anyone able to help figuring this out?
I think I can create a demo repo in some of my free time. I'll add it to my Todo
Thanks!
Sorry for the delay. I have been trying to avoid little things as much as possible for a while.
I have just created the demo repo: (https://github.com/Metehan-Altuntekin/svelte-jsoneditor-pnpm-monorepo-issue-demo)
With the latest version of everything, the issue seems to be fixed.
That is good news, thanks for the feedback 🎉
I am getting this error when I try to use it in a Svelte workspace in a monorepo:
"Failed to resolve import "ajv/dist/runtime/validation_error" from "node_modules.vite\deps\svelte-jsoneditor.js?v=dab92afd". Does the file exist?"
When I check
node_modules
, ajv appears to be not installed:When I add ajv as a dependency to the workspace, it appears in the
node_modules
error goes away.System: Windows 10 Pro Node: 18.13.0 PNPM: 8.1.1
Project: https://github.com/cozemble/monorepo Workspace: https://github.com/cozemble/monorepo/tree/main/frontend/datatable