next.js: [NEXT-1103] Cannot read properties of null (reading 'useState') with Context Wrapper

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103
    Binaries:
      Node: 19.1.0
      npm: 8.19.3
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.1-canary.11
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps)

Link to the code that reproduces this issue

https://github.com/Kiwi-Biosciences/debug

To Reproduce

When trying to build the project, it will fail with the following error:

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

Describe the Bug

The build fails.

Expected Behavior

The build should succeed, as there are no visible logic or syntax errs.

Which browser are you using? (if relevant)

Firefox 112.0

How are you deploying your application? (if relevant)

AWS Amplify

NEXT-1103

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 31 (11 by maintainers)

Most upvoted comments

This is now happening when upgrading next from v13.3.4 into v13.4.0. Not necessarily with

…(reading ‘useState’)

in the message, but all other hooks coming from react.

The builds are failing only when deployed on Vercel.

Related.

For the original bug reproduction (https://github.com/Kiwi-Biosciences/debug), the cause was using async components inside a “use client” file, which is disallowed.

Hi, another dev trying to use app dir alongside existing pages on a production app here.

I can reproduce this error using latest relevant packages:

"next": "^13.4.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",

Build does only fail on Vercel, local next build is fine.

Specifics

We encountered this issue with swiper package, however the specific package is irrelevant, it’s caused probably by Next bundling the third-party packages. This package is used only in pages routes.

Workaround

I added this package to transpilePackages which made the build finish.

Similar issues

Same thing here, the build works locally, but fails on vercel.

Thanks @jeffrafter, downgrading to Next 13.2.4 did work for now. Hopefully Next and/or Nx can solve this issue.