Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All validation libraries from optional dependencies are installed in dev environment #351

Open
1 task done
vladshcherbin opened this issue Feb 19, 2024 · 6 comments
Open
1 task done
Labels
enhancement New feature or request later May be worked on in the future.

Comments

@vladshcherbin
Copy link

  • Before posting an issue, read the FAQ and search the previous issues.

Description
Found in #350

Currently all validation libraries are installed even when they are not used (all optional dependencies).
This is not good for a lot of reasons - wasted space, traffic, package stats update, etc.

From referenced issue it's also visible that some bundlers (vite in my case) are trying to process/include this dependencies in the bundle which is also not desired.

You can see a massive library size increase: https://packagephobia.com/result?p=sveltekit-superforms@2.3.0

image

I've tried different combinations of commands with no luck to install only what I need:

yarn add sveltekit-superforms
yarn add sveltekit-superforms valibot
yarn add sveltekit-superforms -D
yarn add sveltekit-superforms valibot -D

A solution should be found on how to get only used packages 🤔

@vladshcherbin vladshcherbin added the bug Something isn't working label Feb 19, 2024
@ciscoheat
Copy link
Owner

This is not accurate, the packages are only installed in a dev environment. Vite/Rollup will only bundle what's referenced in the project. For example, when I build with Valibot:

2024-02-19 13_19_07-+page svelte - sf2-bundle - Visual Studio Code

@vladshcherbin
Copy link
Author

I've added a reproduction with screenshot - https://github.com/vladshcherbin/svelte-superforms.

From screenshot it's visible vite is at least processing zod-to-json-schema which is not used anywhere in the app.

From superforms & valibot dependency commit it's visible how many unused packages are installed which is also not desirable for the reasons above.

I'd be happy to help solve but have no idea except splitting adapters into different packages and install only needed e.g.

yarn add sveltekit-superforms sveltekit-superforms-adapters/valibot valibot

@ciscoheat
Copy link
Owner

What's installed during development is not an issue, I'm concerned with the final bundle size. You can even look through the non-minified output to see that Zod is never referenced anywhere.

@ciscoheat
Copy link
Owner

About the circular dependency, it doesn't happen with pnpm, so maybe it's a yarn issue.

@vladshcherbin
Copy link
Author

Well, that's the best reproduction I can give. I do believe both issues should be solved and only required libraries be installed but I respect your opinion, direction and ideas.

Sorry for opening so many issues and thanks for the library, everything else seems to be working and simplifying forms is a huge relief 😇

Hopefully this ones can be resolved some day 🙌

@ciscoheat ciscoheat added enhancement New feature or request later May be worked on in the future. and removed bug Something isn't working labels Feb 19, 2024
@ciscoheat ciscoheat changed the title All validation libraries from optional dependencies are installed All validation libraries from optional dependencies are installed in dev environment Feb 20, 2024
@gregmsanderson
Copy link

If it helps at all, I came across this issue while investigating this warning:

vite v5.1.3 building for production...
[plugin:vite:resolve] Module "node:dns/promises" has been externalized for browser compatibility, imported by "/node_modules/@vinejs/vine/build/chunk-TVEIURSI.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

I've been playing with superforms (via formsnap). It's great! But I was puzzled where @vinejs was coming from, having not installed it. From: npm ls --all I noticed a peer dependency.

I agree that (in my case) @vinejs won't be in the production bundle ... however its presence does seemingly result in that Vite warning while bundling it. Vine appears to be form validation focused on Node apps and so while they might change it at their end, not including it as a peer dependency would also avoid that warning. I would assume people would install their choice of validation library separately.

I do agree it's an enhancement since a warning isn't an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request later May be worked on in the future.
Projects
None yet
Development

No branches or pull requests

3 participants