Nextjs and 'Cannot read properties of null' error

When running in production (inside Docker), a strange error about React hooks being null happened. Downgrade fixed it.

Profile pictureToni Petrina
Published on 2024-01-131 min read
  • #React
  • #nextjs

The following error happens only in production:

TypeError: Cannot read properties of null (reading 'useContext')

For context, the app is built as standalone as it is deployed with a Docker container (not on Vercel).

The error makes no sense as it is saying the React hook is being null. The error location points to a swr library and a line of code that merely uses the hook.

The solution: downgrade from 13.4.6 to 13.4.5.

Change code theme: