gerhardsletten / react-reader

An ePub-reader for React, powered by Epub.js
https://react-reader.metabits.no
Apache License 2.0
676 stars 130 forks source link

Cannot read properties of undefined (reading 'Component') error installing the version 2.0.4 #167

Closed gabrielaRazo closed 7 months ago

gabrielaRazo commented 9 months ago

I noticed that the new version (2.0.4) had an error on the node-modules. It is a simple export error that I solved on local but when I try to upload my app the same error is shown on the pipeline. It is possible to solve that error without having to install the 1.2.2 version?

Screenshot 2023-12-20 110536

gerhardsletten commented 8 months ago

@gabrielaRazo In the project where this is happening, ensure react is installed as a dependency

jordant97 commented 8 months ago

have the same issue, was on nextjs 14

gerhardsletten commented 8 months ago

@jordant97 Would you create a sample-repo?

jordant97 commented 8 months ago

My bad, got it working following #125

gerhardsletten commented 8 months ago

@jordant97 Great to hear, then I close this again

robyn3choi commented 7 months ago

I'm getting this error after upgrading to 2.0.4. I'm not sure how jordant97 used #125 to solve it. Adding a height and width to the component's parent element didn't help.

robyn3choi commented 7 months ago

I'm using react v18.2.0 and next v14.1.0

gerhardsletten commented 7 months ago

@robyn3choi Can you make a test repo where this happen?

robyn3choi commented 7 months ago

Sure, here's a test repo - https://github.com/robyn3choi/react-reader-bug. Running yarn dev and going to localhost:3000 will result in that error.

gerhardsletten commented 7 months ago

@robyn3choi Try to upgrade to npm i react-reader@2.0.9 and change your code to: (you need a height/width for parent element)

<main className="h-screen w-screen">
  <ReactReader
    url="https://react-reader.metabits.no/files/alice.epub"
    location={location}
    locationChanged={setLocation}
  />
</main>

The problem was that react-reader's package also need to have and exports field and NextJS was not able to load the es-module with the module field

"exports": {
  ".": {
    "import": {
      "types": "./dist/index.d.ts",
      "default": "./dist/react-reader.es.js"
    },
    "require": {
      "types": "./dist/index.d.ts",
      "default": "./dist/react-reader.umd.js"
    }
  }
},
robyn3choi commented 7 months ago

Thanks, it's working for me now!

gerhardsletten commented 7 months ago

Great!