Skip to content

Plyr static import breaks in nodejs >=21 environment #2853

Open
@AlexShukel

Description

@AlexShukel

Problem

When running next ssr (in nodejs environment), the static import from "plyr" fails with message ReferenceError: document is not defined. This is because plyr decides whether it is in browser by this check: typeof navigator === "object". However, since node version 21.0.0 it is not correct - see nodejs/node#50269

Expected behaviour

Next build doesn't fail.

Actual behaviour

Build fails with error ReferenceError: document is not defined.

Steps to reproduce

Try to build next.js app with node >=21 and ssr.

Console errors

info  - Linting and checking validity of types  
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data ..ReferenceError: document is not defined
    at C:\Git\alcs\4.Implementation\alcs\java\alcs-react\react-app\node_modules\.pnpm\[email protected]\node_modules\plyr\dist\plyr.js:302:21
    at C:\Git\alcs\4.Implementation\alcs\java\alcs-react\react-app\node_modules\.pnpm\[email protected]\node_modules\plyr\dist\plyr.js:311:5
    at C:\Git\alcs\4.Implementation\alcs\java\alcs-react\react-app\node_modules\.pnpm\[email protected]\node_modules\plyr\dist\plyr.js:2:83
    at Object.<anonymous> (C:\Git\alcs\4.Implementation\alcs\java\alcs-react\react-app\node_modules\.pnpm\[email protected]\node_modules\plyr\dist\plyr.js:5:3)
    at Module._compile (node:internal/modules/cjs/loader:1554:14)
    at Object..js (node:internal/modules/cjs/loader:1706:10)
    at Module.load (node:internal/modules/cjs/loader:1289:32)
    at Function._load (node:internal/modules/cjs/loader:1108:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)

Related to #2770

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions