-
Notifications
You must be signed in to change notification settings - Fork 56
Description
I am using plyr-react in a Next.js 14.0.1 environment (also tried with v13) and pages using plyr-react (5.3.0) fail to load or build with errors of type "ReferenceError: document is not defined" node_modules\plyr\dist\plyr.js:302:21
From my understanding, it seems the runtime tries to access the document object where there isn't one, like when running in a server environment. These errors can be fixed by checking validity of the document object before accessing it, but I don't think this is a proper fix, it seems the code is being run within a context it shouldn't be run into.
Windows 10, Node.js 21.1.0, Next.js 14.0.1, plyr-react 5.3.0, react 18.2.0
FYI I didn't have this problem when I worked on my site about 6 months ago, but now I upgraded everything I have it all the time, this blocks the build.
Steps to reproduce:
- install latest next.js and example app using: npx create-next-app@latest
- npm install plyr-react
- into the app's src/app/page.tsx, import plyr and and a tag in the Home function.
import Plyr from "plyr-react"
import "plyr-react/plyr.css"
(...)
<Plyr (...) />
- npm run dev
- open page in browser and see the error "ReferenceError: document is not defined"