question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NextJs 12: Named export `set` not found

See original GitHub issue

Describe 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

  1. Create a new NextJS project on v12
  2. Install @hookform/resolvers
  3. Try to use any resolver (e.g. zod)
  4. 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:closed
  • Created 2 years ago
  • Reactions:61
  • Comments:82 (22 by maintainers)

github_iconTop GitHub Comments

62reactions
jorisrecommented, Nov 1, 2021

Hey all 👋🏻 I’m working on that issue, I’ll back to you soon as possible

23reactions
allwdcommented, Oct 31, 2021

@mrodrigues95 I faced the same issue just now. Fixed it temporarily by replacing import { yupResolver } from '@hookform/resolvers/yup'; with import { yupResolver } from '@hookform/resolvers/yup/dist/yup.umd';. Maybe it’s going to work for you as well.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found