NextJs 12: Named export `set` not found
See original GitHub issueDescribe the bug
I’ve upgraded to NextJS v12 which supports ES modules out of the box and now I’m getting the following error whenever I try to load any page that imports uses zodResolver
.
file:///node_modules/@hookform/resolvers/dist/resolvers.mjs:1
import{get as r,set as o}from"react-hook-form";var a=function(a,e){var f={};for(var t in a){var n=r(e,t);o(f,t,Object.assign(a[t],{ref:n&&n.ref}))}return f};export{a as toNestError};
error - unhandledRejection: 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:
import pkg from 'react-hook-form';
const {get: r,set: o}from"react-hook-form";var a=function(a,e){var f={};for(var t in a){var n=r(e,t);o(f,t,Object.assign(a[t],{ref:n&&n.ref}))}return f};export{a: toNestError} = pkg;
To Reproduce
- Create a new NextJS project on v12
- Install
@hookform/resolvers
- Try to use any resolver (e.g. zod)
- See error
import { zodResolver } from '@hookform/resolvers/zod';
export const useZodForm = ({
schema,
...formConfig
}) => {
return useForm({
...formConfig,
resolver: zodResolver(schema),
});
};
Expected behavior Import is resolved.
Additional context
"@hookform/resolvers": "^2.8.2"
, "react-hook-form": "^7.18.0"
, "next": "^12.0.2"
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:61
- Comments:82 (22 by maintainers)
Top Results From Across the Web
React-hook-form build problem when upgrading nextjs to ...
SyntaxError : Named export 'set' not found. The requested module react-hook-form is a CommonJS module, which may not support all ...
Read more >Error message when compiling with NextJs 12.0.2 #6961
SyntaxError : Named export 'set' not found. The requested module 'react-hook-form' is a CommonJS module, which may not support all ...
Read more >module-not-found - Next.js
A module not found error can occur for many different reasons: The module you're trying to import is not installed in your dependencies;...
Read more >Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks.
Read more >Advanced Features: Next.js Compiler
Learn about the Next.js Compiler, written in Rust, which transforms and minifies your Next.js application.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey all 👋🏻 I’m working on that issue, I’ll back to you soon as possible
@mrodrigues95 I faced the same issue just now. Fixed it temporarily by replacing
import { yupResolver } from '@hookform/resolvers/yup';
withimport { yupResolver } from '@hookform/resolvers/yup/dist/yup.umd';
. Maybe it’s going to work for you as well.