Undefined useRef issue with NextJS 13 Pages router and react library built with Parcel

130 views Asked by At

I have a React component library built with [email protected], which throws this when using with nextjs 13/14, just pages router, not even with app router.

The error is:

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

Which means the react variable from import * as React from 'react' is undefined as I understand it.

I created a minimal reproduction of the issue:

Nextjs App: https://github.com/yyyyaaa/reproduction-next-parcel-pages-bug

Library: https://github.com/yyyyaaa/my-react-lib

Reproduction steps:

  • Clone both repo, run npm install in both repo
  • in library folder, run npm link && npm run build. This creates an npm link and build the library.
  • in next app folder, run npm link "my-react-lib", this linked the local library code. Then npm run dev , you'll see the error.
0

There are 0 answers