Comments (33)
Thanks @bluebill1049 :)
I've added some examples in #60 (comment)
from resolvers.
This is a minimal reproduction: https://github.com/avin-kavish/cra-ts-hook-form-resolver-issue
The solution I have in mind is to have seperate export files for the different resolvers.
import yupResolver from '@hookform/resolvers/yup'
import joiResolver from '@hookform/resolvers/joi'
import superstructResolver from '@hookform/resolvers/superstruct'
This way typescript won't run into the missing packages.
from resolvers.
After playing with rollup config and TS I got the result below :
No more error :)
This is still work in progress, needs to test more umd bundle.
from resolvers.
Will try to open a PR in the next couple of days.
from resolvers.
This a stop-gap method but it works.
- Manually comment out all the code that's generating an error.
(In my case, in
index.d.ts
, I commented out the export for Joi and Superstruct. Similarly, comment out thejoi.d.ts
andsuperstruct.d.ts
files)- Install Package-Patch and generate a patch.
- Add the patch to the
post-install
script inpackage.json
.That's all, now every time you run
npm i
the patch will be applied automatically, and when there's a new update for the Resolver it will notify you to check if the patch is still needed.
Thanks for sharing the solution, wondering if there is some way we can prevent this in the lib level.
from resolvers.
@bluebill1049 👋🏻
The new rollup config solve this issue, but I need more time to test all bundle (umd, cjs(ie11)...) but I was slowed down by the issue with ajv.
I think, it will be good tomorrow :)
from resolvers.
@bluebill1049 👋🏻
The new rollup config solve this issue, but I need more time to test all bundle (umd, cjs(ie11)...) but I was slowed down by the issue with ajv.
I think, it will be good tomorrow :)
oh wow, that's awesome. let's move Avj out the equation for now. I will mostly like to revert that commit until we have a good fix for it. honestly, i would love to solve this problem first and potentially unblock zod as well.
from resolvers.
Why not having one package per resolver?
As far as I can tell, this (https://github.com/react-hook-form/resolvers/blob/master/src/yup.ts) has no dependency to other module form the package.
This is actually how I fixed it in our project, just by extracting the content of yup.ts
in one of our module.
from resolvers.
I solved this issue by adding
superstruct
version0.8.3
to my dependencies.
yarn add [email protected]
Thanks, but that's pretty bad... we probably need a better solution for this. any help is appreciated.
from resolvers.
This a stop-gap method but it works.
-
Manually comment out all the code that's generating an error.
(In my case, in
index.d.ts
, I commented out the export for Joi and Superstruct. Similarly, comment out thejoi.d.ts
andsuperstruct.d.ts
files) -
Install Package-Patch and generate a patch.
-
Add the patch to the
post-install
script inpackage.json
.
That's all, now every time you run npm i
the patch will be applied automatically, and when there's a new update for the Resolver it will notify you to check if the patch is still needed.
from resolvers.
It looks like
superstruct
in the dev dependencies needs upgrading. Their latest version (0.10.12
) defines the Struct class differently from0.8.3
. That's what is causing the issue in the first place.
sadness.... #16
from resolvers.
❤️ @jorisre is the hero! please share some appreciation towards his hard work and here is a beta: @hookform/[email protected]
and help us to test. ❤️
from resolvers.
Was coming here to mention that skipLibCheck: true
was the culprit for us but I see other people found it out before.
Glad you found a proper solution. 👏 @jorisre
(But also, skipLibCheck: true
divided our build time by 4... -_-)
from resolvers.
@qventura i think this issue is resolved by the latest update from @jorisre.
from resolvers.
which version? and screenshot?
from resolvers.
"@hookform/resolvers": "0.0.5"
I just copied the yup resolver code and bypassed it for now, will post a screenshot when I can. It's happening with CRA + Typescript.
The error is basically the types for superstruct
cannot be found. Once I installed 'superstruct', there was another error about generic parameters not being passed to superstruct type.
Basically, this type requires at least one generic parameter,
But here there is none,
Line 46 in ff82c5f
maybe this will fix it?
schema: Superstruct.Struct<TFieldValues>
Will get back to you with screenshots.
from resolvers.
Do you have any solution in mind?
from resolvers.
I am seeking some evidence for this issue first before making any adjustments or changes. Thanks for sharing your solutions.
from resolvers.
Thanks @avin-kavish we can definitely try that.
from resolvers.
I just tried your repo, if you have installed the dependency it's working as expected.
from resolvers.
Is this still an issue?
from resolvers.
I have same issue in yupResolver (v0.0.6).
And I do not want to include other type definition packages.
This solution is lgtm.
from resolvers.
Will try to open a PR in the next couple of days.
That would be awesome! thanks @avin-kavish
from resolvers.
I'm having the same problem.
I'm using yup for validation so I only installed Yup. Type checking is reporting the other two modules as missing.
After I installed both @hapi/joi
, superstruct
, and their type definitions, now I'm getting this error.
Adding Superstruct.Struct<TFieldValues>
seems to fix the error on the local machine but won't help you want to deploy it on CI/CD pipeline server or anything automated.
from resolvers.
I solved this issue by adding superstruct
version 0.8.3
to my dependencies.
yarn add [email protected]
from resolvers.
It looks like superstruct
in the dev dependencies needs upgrading. Their latest version (0.10.12
) defines the Struct class differently from 0.8.3
. That's what is causing the issue in the first place.
from resolvers.
I was wondering why I didn't have the same problem and while I still don't get why it doesn't break at runtime (maybe webpack tree shaking?) I think it doesn't break the build because I have skipLibCheck set to true in my tsconfig.json (😢 ).
This is going to become a real problem as you keep supporting more libraries.
This package could maybe use Node 14 exports
option? It won't fix the issue for users using previous versions, but it should allow to import { yupResolver } from '@hookform/resolvers/yup'
for everyone running tsc with Node >14
For other versions of Node, one quick fix right now is to do import ( yupResolver ) from '@hookform/resolvers/dist/yup';
from resolvers.
I was wondering why I didn't have the same problem and while I still don't get why it doesn't break at runtime (maybe webpack tree shaking?) I think it doesn't break the build because I have skipLibCheck set to true in my tsconfig.json (😢 ).
This is going to become a real problem as you keep supporting more libraries.
This package could maybe use Node 14
exports
option? It won't fix the issue for users using previous versions, but it should allow toimport { yupResolver } from '@hookform/resolvers/yup'
for everyone running tsc with Node >14For other versions of Node, one quick fix right now is to do
import ( yupResolver ) from '@hookform/resolvers/dist/yup';
yea, thanks @julienfouilhe. This one gives me a headache and nightmares right now. hope to find a solution soon. 😖
from resolvers.
oh wow, @jorisre you are a legend!
from resolvers.
I'm having same error - just using yup but it wants me to add superstruct and joi too
I'm using "@hookform/resolvers": "^0.1.1",
from resolvers.
I was wondering why I didn't have the same problem and while I still don't get why it doesn't break at runtime (maybe webpack tree shaking?) I think it doesn't break the build because I have skipLibCheck set to true in my tsconfig.json ( ).
This is going to become a real problem as you keep supporting more libraries.
This package could maybe use Node 14
exports
option? It won't fix the issue for users using previous versions, but it should allow toimport { yupResolver } from '@hookform/resolvers/yup'
for everyone running tsc with Node >14For other versions of Node, one quick fix right now is to do
import ( yupResolver ) from '@hookform/resolvers/dist/yup';
I tried this but get error:
Uncaught Error: Cannot find module '@hookform/resolvers/dist/yup'
at webpackMissingModule
from resolvers.
hey @jorisre any luck with this fix you were trying. really appreciate your effort here, I think if there is no good solution I may going to try to turn this repo into a mono repo and have each separate packages... it's annoying but i guess there is no other better solution unless if you have some luck with the build.
from resolvers.
For TS users, as a workaround, you can set skipLibCheck: true
in your tsconfig.json
from resolvers.
Related Issues (20)
- Valibot - Optional not found
- issue: Valibot resolver optional not Found HOT 1
- AJV Resolver - When ajv schema contains `default` for certain properties, `getValues()` returns the form data with properties overwritten
- typescript type error for yupResolver HOT 22
- Not Possible to use Zod omit on schema passed to resolver HOT 1
- Zod continues to throw errors while using async refinements with react hook form when zod resolver mode is set to async HOT 2
- Issue with valibotResolver causing unexpected form submission behavior HOT 3
- typescript problem in AJV resolver HOT 1
- Fields configured as mandatory are not being validated and are ignored.
- errors object creating circular structure with yup resolver
- Zod superRefine does not correctly revalidate the form on change HOT 2
- Issue with Resolvers tranform
- Extend typeboxResolver with additional types; getting "Unknown type" in Visit3
- AJV resolver is async mode is not working
- Support `@effect/schema` HOT 4
- when type of input is radio,valueAsNumber dont work anymore HOT 1
- `Joi` resolver crashes on `File` validation
- When using `classValidatorResolver`, combining `@IsOptional()` with `@Length()` makes the field required
- [Zod]: Resolver does not validate to reflect correct error state without manual form.trigger() HOT 8
- zodResolver / superRefine / useFieldArray: useForm errors are not updated to reflect zodResolver errors HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resolvers.