将 nextjs 升级到版本 12 时的 React-hook-form 构建问题

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

当我将 nextjs 升级到 版本 12 并且我 运行 yarn dev 它在反应中有问题-挂钩形式库:

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

谁能帮我解决这个错误?

导入您的 yupResolver 略有不同。

相对于:

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

做:

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

react hook 7.22.5 版本修复了这个错误

正如 David Cingolani 提到的,此问题已在 react-hook-form 版本 7.22.5 之后得到修复。

将库更新到最新版本运行

npm i react-hook-form@latest

yarn add react-hook-form@latest

要更新到最新版本或使用后缀“@7.22.5”更新到准确的版本。

E.g: npm i react-hook-form@7.22.5