-
Notifications
You must be signed in to change notification settings - Fork 15
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
NextJS static build throws error unless errors object passed to ErrorMessage #91
Comments
Same here. Somehow this error was not triggered using next 11, but broke as soon as we upgraded to next 12. Simple replication sandbox here: https://codesandbox.io/s/cocky-hellman-toj9b9?file=/pages/index.js |
I can confirm this. Both with a |
I've just come across this issue as well. {
"@hookform/error-message": "^2.0.1",
"next": "13.0.6",
"react-hook-form": "^7.40.0"
} |
Same error with an NX workspace setup using webpack. It seems this library doesn't import the same version of the context |
Anyone found a workaround for this? Running into it with Vitest. We can just mock the component of course, but it would be nice to be able to include its functionality in our unit testing. |
Same error here, passing errors directly from the parent component solved the error.
seems like methods from useFormContext returns 'undefined', still don't know why. |
Same issue here after update to |
I've been using ErrorMessage with no issues on NextJS client-rendered pages. Based on the documentation, I haven't been passing the
errors
object to the ErrorMessage component since I'm using a FormProvider.However, I just tried to use an ErrorMessage in a form on a NextJS statically exported page and it throws an error that says
TypeError: Cannot read properties of null (reading 'formState')
.After looking through the issues here and reading #52, I tried fetching the
errors
object inside my component usinguseFormContext
, and passing this to the ErrorMessage. It seems to have resolved the issue.This workaround works for me, but I wanted to see if this is expected behavior when exporting a static page.
Versions:
NextJS v12.1.0
React-Hook-Form v7.27.1
@hookform/error-message v2.0.0
The text was updated successfully, but these errors were encountered: