8

Edit

So, what turned out to be the problem? I had two instances of React and ReactDOM contributing to the served bundle of applicationB. I was misled in diagnosing the problem-space and therefore the question(s)/appeal raised below is a little all-over-the-place. What should be taken away, in the hope it may help someone else in this position:

Background:

I am trying to test an npm package (packageA) I am developing locally. It is a React Component that manages an animation using gsap. I am consuming it in applicationB--itself is a Remix app,--through the use of npm link. However, I get the following error when trying to introduce packageA to applicationB:

// 1. warning logged to console
Uncaught TypeError: Cannot read properties of null (reading 'useEffect')
    at ki (react.development.js:1634:21)
    at Mk (PackageAComponent.tsx:26:3)
    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 HTMLUnknownElement.callCallback2 (react-dom.development.js:4164:14)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)
    at invokeGuardedCallback (react-dom.development.js:4277:31)
    at beginWork$1 (react-dom.development.js:27451:7)
    at performUnitOfWork (react-dom.development.js:26560:12)
const PackageAComponent = (props: Props) => {

// 1. culprit line of failure
  useEffect(() => {
    ... stuff happening
  }, []);

  return (
    ...
  );
};

Relevant Notes

packageA output of "npm ls react react-dom"
  • react@18.2.0
  • react-dom@18.2.0
applicationB output of "npm ls react react-dom"
  • react@18.2.0
  • react-dom@18.2.0

I am unsure what other data would be relevant to provide and how best to troubleshoot this so that I may provide more helpful insights. Sorry team.

slackermorris
  • 368
  • 3
  • 11
  • React is null. It looks like one app isn't built/bundled with an instance of React? We would need to see more of your project setup/configuration/etc and what you are doing (*i.e. reproduction steps*) to likely provide any more insight/assistance. – Drew Reese Aug 21 '22 at 23:01
  • @DrewReese Thanks for the reply! I am using esbuild to bundle `packageA` for the browser. `applicationB` is a Remix application. Because `packageA` is dependant on browser based APIs to run, I handle its rendering as recommended [here](https://remix.run/docs/en/v1/guides/constraints#rendering-with-browser-only-apis). For reproduction: 1) I generate a build of `packageA`. 2) I run `npm link ../packageA` from `applicationB`. 3) I boot up a local dev server in `applicationB`, itself hosting a React Application that consumes `packageA`. – slackermorris Aug 22 '22 at 08:39
  • Were you able to find any solutions to this @slackermorris – Aakash Sharma Jun 15 '23 at 21:36

0 Answers0