egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.01k stars 217 forks source link

Issue with react hook library `Cannot read properties of null (reading 'useMemo')` #1021

Open konsalex opened 11 months ago

konsalex commented 11 months ago

Hey folks,

Not sure what is exactly the problem, but solved it by switching back to native tsc for transpiling the library.

I have a monorepo, and tried to create a react hook that I would use to a sibling package in the monorepo. Unfortunately, I faced an issue which I couldn't resolve.

The issue is also attached as an image:

react-dom.development.js:26923 Uncaught TypeError: Cannot read properties of null (reading 'useMemo')
    at useMemo2 (react.development.js:1650:21)
    at useTTQuery (index.tsx:16:18)
    at ReproduceComp (App.tsx:4:20)
    at renderWithHooks (react-dom.development.js:16305:18)
    at mountIndeterminateComponent (react-dom.development.js:20074:13)
    at beginWork (react-dom.development.js:21587:16)
    at beginWork$1 (react-dom.development.js:27426:14)
    at performUnitOfWork (react-dom.development.js:26557:12)
    at workLoopSync (react-dom.development.js:26466:5)

CleanShot 2023-10-12 at 14 21 28@2x

Not sure what exactly is the cause of this issue, but pretty sure it's something to do with the building process, as with pure tsc it works as expected, as there is not any weird hook violation as described.

The reproduction link: https://github.com/konsalex/tsup-reproduction-react

Upvote & Fund

Fund with Polar

knames commented 5 months ago

also experiencing similar, swapped from tsc to tsup and my context is blowing up in tests

gabitoesmiapodo commented 1 month ago

I'm having the same issue.