Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plyr-react library with Next.js 14 #60862

Closed
1 task done
timomedia opened this issue Jan 19, 2024 · 7 comments
Closed
1 task done

Plyr-react library with Next.js 14 #60862

timomedia opened this issue Jan 19, 2024 · 7 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@timomedia
Copy link

timomedia commented Jan 19, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/hidden-frost-mpdjj?file=%2Fsrc%2FHLS.tsx

To Reproduce

I am using plyr-react in a Next.js 14.1.0 environment and pages using plyr-react (5.3.0) fail to load or build with errors of type

Current vs. Expected behavior

⨯ node_modules\plyr\dist\plyr.min.mjs (1:7201) @ document
 ⨯ ReferenceError: document is not defined
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./components/player.tsx:11:68)
    at (ssr)/./components/player.tsx (\.next\server\app\[movie]\page.js:249:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./app/[movie]/movieDetail.tsx:7:76)
    at (ssr)/./app/[movie]/movieDetail.tsx (\.next\server\app\[movie]\page.js:194:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
null

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

I didn't have this problem when I worked on my site with next.js 14.0.0, but now I upgraded everything I have it all the time, this blocks the build.

@timomedia timomedia added the bug Issue was opened via the bug report template. label Jan 19, 2024
@brkcrdk
Copy link

brkcrdk commented Jan 20, 2024

You got to import plyr dynamically.

@johnsi15
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/hidden-frost-mpdjj?file=%2Fsrc%2FHLS.tsx

To Reproduce

I am using plyr-react in a Next.js 14.1.0 environment and pages using plyr-react (5.3.0) fail to load or build with errors of type

Current vs. Expected behavior

⨯ node_modules\plyr\dist\plyr.min.mjs (1:7201) @ document
 ⨯ ReferenceError: document is not defined
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./components/player.tsx:11:68)
    at (ssr)/./components/player.tsx (\.next\server\app\[movie]\page.js:249:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./app/[movie]/movieDetail.tsx:7:76)
    at (ssr)/./app/[movie]/movieDetail.tsx (\.next\server\app\[movie]\page.js:194:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
null

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

I didn't have this problem when I worked on my site with next.js 14.0.0, but now I upgraded everything I have it all the time, this blocks the build.

Hi @timomedia I used Dynamic Imports as @brkcrdk mentioned, I'll leave you an example:

export function Video() {
  const [importedComponent, setImportedComponent] = useState<ReactElement | null>(null)

  useEffect(() => {
    const importComponent = async () => {
      const myModule = await import('plyr-react')
      const Plyr = myModule.default
      setImportedComponent(<Plyr {...plyrProps} />)
    }

    importComponent()
  }, [])

  return (
    <section className='aspect-video mx-16 mt-20 mb-28'>
      {importedComponent}
    </section>
  )
}

@timomedia
Copy link
Author

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/hidden-frost-mpdjj?file=%2Fsrc%2FHLS.tsx

To Reproduce

I am using plyr-react in a Next.js 14.1.0 environment and pages using plyr-react (5.3.0) fail to load or build with errors of type

Current vs. Expected behavior

⨯ node_modules\plyr\dist\plyr.min.mjs (1:7201) @ document
 ⨯ ReferenceError: document is not defined
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./components/player.tsx:11:68)
    at (ssr)/./components/player.tsx (\.next\server\app\[movie]\page.js:249:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
    at eval (./app/[movie]/movieDetail.tsx:7:76)
    at (ssr)/./app/[movie]/movieDetail.tsx (\.next\server\app\[movie]\page.js:194:1)
    at __webpack_require__ (\.next\server\webpack-runtime.js:33:42)
null

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local)

Additional context

I didn't have this problem when I worked on my site with next.js 14.0.0, but now I upgraded everything I have it all the time, this blocks the build.

Hi @timomedia I used Dynamic Imports as @brkcrdk mentioned, I'll leave you an example:

export function Video() {
  const [importedComponent, setImportedComponent] = useState<ReactElement | null>(null)

  useEffect(() => {
    const importComponent = async () => {
      const myModule = await import('plyr-react')
      const Plyr = myModule.default
      setImportedComponent(<Plyr {...plyrProps} />)
    }

    importComponent()
  }, [])

  return (
    <section className='aspect-video mx-16 mt-20 mb-28'>
      {importedComponent}
    </section>
  )
}

Thank you

@igoroalonge
Copy link

igoroalonge commented Feb 20, 2024

Just import using the dynamic function like:

import dynamic from 'next/dynamic'
const Plyr = dynamic(() => import("plyr-react"), { ssr: false });

@kwiromeo
Copy link

kwiromeo commented Apr 8, 2024

I've found an easier way to fix it, just import using the dynamic function like:

import dynamic from 'next/dynamic'
const Plyr = dynamic(() => import("plyr-react"), { ssr: false });

This fixed my issue.

@timneutkens
Copy link
Member

There's an issue on that library: chintan9/plyr-react#873. This is not a Next.js issue but an issue in the library used as it's reading document in the module scope. document is not available in server environments. Additionally this indicates that the library is not fully compatible with React as it tries to read/modify document outside of useEffect.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

6 participants