Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-hook-form build problem when upgrading nextjs to version 12

When I upgrade nextjs to version 12 and I run yarn dev it has a problem in react-hook-form library:

SyntaxError: Named export 'set' not found. The requested module react-hook-form is a CommonJS module, which may not support all module.exports as named exports. CommonJS modules can always be imported via the default export, for example using ....

Can anyone help me fix this error?

like image 641
Tuan Nguyen Avatar asked Nov 01 '21 04:11

Tuan Nguyen


3 Answers

import your yupResolver slightly differently.

as opposed to:

import {yupResolver} from '@hookform/resolvers/yup';

do:

import {yupResolver} from '@hookform/resolvers/yup/dist/yup';
like image 184
neo Avatar answered Oct 06 '22 13:10

neo


As David Cingolani mentioned, this problem was fixed in react-hook-form after version 7.22.5.

To update the lib to the latest version run

npm i react-hook-form@latest

or

yarn add react-hook-form@latest

To update to the most recent version or use the suffix "@7.22.5" to update to the exact version.

E.g: npm i [email protected]

like image 33
Arthur Costa Avatar answered Oct 06 '22 14:10

Arthur Costa


with the version 7.22.5 of react hook form this error was fixed

like image 2
David Cingolani Avatar answered Oct 06 '22 12:10

David Cingolani