Open kmcaloon opened 2 years ago
I don't recall if the pages directory uses server components by default like the app directory does but if so I believe that can be an issue and you have to add 'use client' At the top. Try console logging in your component to identify if it's a server or client component.
Sorry, I forgot to mention that I've tried both with and without 'use cllient' at the top and I get the same error. I'm pretty sure it shouldn't matter though as long as nothing within the app directory is importing it.
If your reproduction matches exactly your setup, you need to add app/layout.tsx
for that to work. Once you enable the app directory next is gonna use that as the root, and you need a root layout to render the basic html structure.
Here's a fork of your reproduction working: https://stackblitz.com/edit/vercel-next-js-n7jjy7?file=next.config.js,app/layout.tsx,pages/index.tsx (not sure why react-hook-form
is not installing on container setup, but just make sure to run yarn
and yarn dev
on the container terminal)
Hi @lukemorales thanks for the work around. Do you know now the reason of why this happens?
I'm also seeing a similiar issue using pages dir with standalone builds. For me removing standalone builds seems to resolve the issue. However, this increases our image sizes so isn't optimal.
I get this error TypeError: Cannot read properties of null (reading 'useRef')
However i do not receive the warning about react hooks used outside a component.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 Binaries: Node: 16.17.0 npm: 5.1.0 Yarn: 1.22.19 pnpm: N/A Relevant packages: next: 13.0.1-canary.3 eslint-config-next: 13.0.0 react: 18.2.0 react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
I have been using
react-hook-form
and after upgrading to Next 13 I am setting the following error related to theiruseForm()
hook. I am not using the new app directory, but when I setexperimental: { appDir: true }
in my next config I get the following error:I opened this issue here first because it seems directly related to the app directory config and wanted to get a better understanding as to what might be affected this before opening an issue with them.
Expected Behavior
App works perfectly fine without the invalid hook warning and type error when
appDiir
is set to false. Since none of the apps components live within the newapp
directory we would expect the behavior to be the same even whenappDir
is enabled.Link to reproduction
https://stackblitz.com/edit/vercel-next-js-aufyu7?file=next.config.js
To Reproduce
Run
next dev
and try to refresh the page and you will see the error.