Module not found: Can't resolve 'react-hook-form'. NextJS

See original GitHub issue

Describe the bug I am using nextjs. All works when running dev but when I do npm run build get an error: Module not found: Can't resolve 'react-hook-form.

To Reproduce

  1. npm run build
  2. Error in console

My code

import { useForm } from 'react-hook-form';
import { Input, Button } from '@/atom/form';

export default function CourseLandingPage({ onSubmit }) {
  const { register, handleSubmit, watch, errors } = useForm();

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <div className='bg-light px-4 py-2'>
        <Button secondary>Create a new course</Button>
      </div>

      <div className='mt-5'>
        <Input
          lg
          name='name'
          label='Course name'
          defaultValue={name}
          refProp={register({ required: true })}
          errors={errors}
          error='This field is required'
        />
      </div>
    </form>
  );
}

My build “react-hook-form”: “^6.15.1”, “next”: “^10.0.6”, “next-auth”: “^3.2.0”, “react”: “16.13.1”,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alextseitlincommented, Feb 19, 2021

After leaving only the page with the form all works… I will have to dig more and see why I have it on my end

0reactions
bluebill1049commented, Feb 19, 2021

ok, let me know if anything I can help, i will close it for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useForm and react-hook-form is giving problems with I use it ...
Try to go to package.json , see if you already have react-hook-form library in it. · run yarn or npm install on your...
Read more >
Module not found: Can't resolve 'react-hook-form-resolvers' #6
Install the module using npm install react-hook-form-resolvers . Then import yupResolver . ... When I look into the node_modules/react-hook-form- ...
Read more >
react-hook-form - npm
Performant, flexible and extensible forms library for React Hooks. Latest version: 7.41.1, last published: a day ago.
Read more >
Get Started | React Hook Form - Simple React forms validation
One of the key concepts in React Hook Form is to register your component into the hook. This will make its value available...
Read more >
Invalid Hook Call Warning - React
You might be using a version of react-dom (< 16.8.0) or react-native (< 0.59) that doesn't yet support Hooks. You can run npm...
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