Git Product home page Git Product logo

Comments (33)

jorisre avatar jorisre commented on May 18, 2024 4

Thanks @bluebill1049 :)

I've added some examples in #60 (comment)

from resolvers.

avin-kavish avatar avin-kavish commented on May 18, 2024 3

This is a minimal reproduction: https://github.com/avin-kavish/cra-ts-hook-form-resolver-issue

image

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.

jorisre avatar jorisre commented on May 18, 2024 3

After playing with rollup config and TS I got the result below :

Screenshot

Capture d’écran 2020-09-16 à 18 31 47

No more error :)
This is still work in progress, needs to test more umd bundle.

from resolvers.

avin-kavish avatar avin-kavish commented on May 18, 2024 2

Will try to open a PR in the next couple of days.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024 2

This a stop-gap method but it works.

  1. 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 the joi.d.ts and superstruct.d.ts files)

  2. Install Package-Patch and generate a patch.
  3. Add the patch to the post-install script in package.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.

jorisre avatar jorisre commented on May 18, 2024 2

@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 avatar bluebill1049 commented on May 18, 2024 2

@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.

qventura avatar qventura commented on May 18, 2024 1

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.

bluebill1049 avatar bluebill1049 commented on May 18, 2024 1

I solved this issue by adding superstruct version 0.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.

10may avatar 10may commented on May 18, 2024 1

This a stop-gap method but it works.

  1. 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 the joi.d.ts and superstruct.d.ts files)

  2. Install Package-Patch and generate a patch.

  3. Add the patch to the post-install script in package.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.

bluebill1049 avatar bluebill1049 commented on May 18, 2024 1

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.

sadness.... #16

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024 1

❤️ @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.

qventura avatar qventura commented on May 18, 2024 1

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.

bluebill1049 avatar bluebill1049 commented on May 18, 2024 1

@qventura i think this issue is resolved by the latest update from @jorisre.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

which version? and screenshot?

from resolvers.

avin-kavish avatar avin-kavish commented on May 18, 2024

"@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,

https://github.com/ianstormtaylor/superstruct/blob/01bdd37aef3357ff6296bf1827737ee11719e4b5/src/struct.ts#L9

But here there is none,

schema: Superstruct.Struct,

maybe this will fix it?

schema: Superstruct.Struct<TFieldValues>

Will get back to you with screenshots.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

Do you have any solution in mind?

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

I am seeking some evidence for this issue first before making any adjustments or changes. Thanks for sharing your solutions.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

Thanks @avin-kavish we can definitely try that.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

I just tried your repo, if you have installed the dependency it's working as expected.

Screen Shot 2020-07-09 at 5 14 31 pm

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

Is this still an issue?

from resolvers.

 avatar commented on May 18, 2024

I have same issue in yupResolver (v0.0.6).
And I do not want to include other type definition packages.

#20 (comment)

This solution is lgtm.

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

Will try to open a PR in the next couple of days.

That would be awesome! thanks @avin-kavish

from resolvers.

10may avatar 10may commented on May 18, 2024

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.

Screenshot from 2020-08-21 15-16-03

After I installed both @hapi/joi, superstruct, and their type definitions, now I'm getting this error.

Screenshot from 2020-08-21 16-51-16

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.

davidepalazzo avatar davidepalazzo commented on May 18, 2024

I solved this issue by adding superstruct version 0.8.3 to my dependencies.

yarn add [email protected]

from resolvers.

davidepalazzo avatar davidepalazzo commented on May 18, 2024

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.

julienfouilhe avatar julienfouilhe commented on May 18, 2024

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.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

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';

yea, thanks @julienfouilhe. This one gives me a headache and nightmares right now. hope to find a solution soon. 😖

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

oh wow, @jorisre you are a legend!

from resolvers.

clairefro avatar clairefro commented on May 18, 2024

I'm having same error - just using yup but it wants me to add superstruct and joi too
image

I'm using "@hookform/resolvers": "^0.1.1",

from resolvers.

clairefro avatar clairefro commented on May 18, 2024

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';

I tried this but get error:

Uncaught Error: Cannot find module '@hookform/resolvers/dist/yup'
    at webpackMissingModule

from resolvers.

bluebill1049 avatar bluebill1049 commented on May 18, 2024

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.

jorisre avatar jorisre commented on May 18, 2024

For TS users, as a workaround, you can set skipLibCheck: true in your tsconfig.json

from resolvers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.