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 self is not defined : Can this library work with React/Next applications ? #18

Open
kishimisu opened this issue Sep 7, 2022 · 6 comments

Comments

@kishimisu
Copy link

I'm trying to use this library in a Next/Vercel project however I get the following error :

ReferenceError: self is not defined
    at eval (webpack-internal:///./libs/canvas-capture.js:5:4)

which seems to indicate that the library doesn't have the window context. Not sure if this is more of a Next setup issue or if the library should work with these frameworks ?

amandaghassaei added a commit that referenced this issue Sep 13, 2022
@amandaghassaei
Copy link
Owner

amandaghassaei commented Sep 13, 2022

Seems like this could be relevant:

I made a branch with this change, try:

npm install git+https://github.com/amandaghassaei/canvas-capture.git#globalObject

let me know if that works and I'll merge it in.

@roygav
Copy link

roygav commented Oct 19, 2022

@amandaghassaei it worked, thanks. But now there's a different error - ReferenceError: window is not defined i'm trying to execute this on node, so i suppose it's not built for node usage 😢

@kishimisu
Copy link
Author

@amandaghassaei Sorry I didn't see your update. I've tested the branch on a new NextJS App and I get the same error as @roygav : ReferenceError: window is not defined

@nguyenvanan18031993
Copy link

@amandaghassaei @roygav roy @indiana-dev in
I got this error too :
ReferenceError: window is not defined
Any update fix it? Please help me

@amandaghassaei
Copy link
Owner

I looked into this a bit - the underlying dependencies in CCapture do not play nicely with the node environment, so unfortunately I think this is not supported right now. Eventually I'd like to redo this whole repo from the ground up and get rid of the dependency on CCapture, but not in the cards anytime soon.

@kevmiota
Copy link

kevmiota commented Nov 11, 2022

@indiana-dev @amandaghassaei I could make it work in nextjs by using dynamic import inside an async function:

async function capture(canvas){
    const CanvasCapture = (await import('canvas-capture')).default;
    CanvasCapture.init( canvas );
    ....
}

This way, we can make sure, that this npm package is not loaded on the server but only on client-side where window is available

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

5 participants