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

ReferenceError: document is not defined #194

Closed
RyanWarner opened this issue Nov 5, 2021 · 4 comments
Closed

ReferenceError: document is not defined #194

RyanWarner opened this issue Nov 5, 2021 · 4 comments

Comments

@RyanWarner
Copy link

I updated from 5.1.0 to 6.0.0 and am now getting the error

ReferenceError: document is not defined

during server side rendering in a NextJS app.

@sindresorhus
Copy link
Owner

sindresorhus commented Nov 5, 2021

Screenfull is meant to run in a browser. The previous version did indeed polyfill document, but I no longer think that's the correct place to handle it. If you want to run a browser-based library on the server, it's up to you to polyfill the required globals.

@tranmanhhung
Copy link

I updated from 5.1.0 to 6.0.0 and am now getting the error

ReferenceError: document is not defined

during server side rendering in a NextJS app.

Dear @RyanWarner
I'm meet this problem,
Can you help me fix this problem, Please.

@RyanWarner
Copy link
Author

@tranmanhhung I solved the problem by downgrading back to version 5.1.0.

@tranmanhhung
Copy link

@tranmanhhung I solved the problem by downgrading back to version 5.1.0.

I just found solved this problem by..
const nativeAPI = (() => {
const unprefixedMethods = methodMap[0];
const returnValue = {};

for (const methodList of methodMap) {
    const exitFullscreenMethod = methodList?.[1];
    if (typeof window === 'object') {
        if (exitFullscreenMethod in document) {
            for (const [index, method] of methodList.entries()) {
                returnValue[unprefixedMethods[index]] = method;
            }

            return returnValue;
        }
    }
}
return false;

})();

line 56 added if (typeof window === 'object') {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants