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: window is not defined while trying to vote with snapshot.js #992

Closed
ChaituVR opened this issue May 1, 2024 · 3 comments · Fixed by #998
Closed

ReferenceError: window is not defined while trying to vote with snapshot.js #992

ChaituVR opened this issue May 1, 2024 · 3 comments · Fixed by #998
Assignees

Comments

@ChaituVR
Copy link
Member

ChaituVR commented May 1, 2024

Expected behavior

Should work without error

Steps to reproduce the behavior

@ChaituVR ChaituVR self-assigned this May 1, 2024
@franzns
Copy link

franzns commented May 1, 2024

Thanks for opening the issue. Let me know if I can help

@fffbbbccc
Copy link
Contributor

fffbbbccc commented May 11, 2024

Hey all, i am experiencing the same issue while i was trying to quickly prototype something in node.
First of all, i had some issues because i didnt check the ethers.js dependencies of snapshot.js and since its using 5.x, the signTypedData function is different (6.x uses signTypedData and 5.x uses _signTypedData).

Anyhow, after getting this out of the way, i realized the this error is coming from this line here

    if (window?.ethereum?.isTrust) {
      domainData.chainId = (await signer.provider.getNetwork()).chainId;
    }

The generated node code looks like this :

if (!((_a = window === null || window === void 0 ? void 0 : window.ethereum) === null || _a === void 0 ? void 0 : _a.isTrust)) return [3 /*break*/, 2];

and i think it throws the error because its trying to access window object without first checking if the window object exists, which ofc doesnt in a node env.
As a horrendous hack, i modified the generated code and replaced it with the following just to see if it works

if (typeof window === 'undefined' || !window.ethereum || !window.ethereum.isTrust) return [3 /*break*/, 2];

which worked. So i figured i am on the right track.

I opened a small pr which will hopefully fix this here : #998

ChaituVR added a commit that referenced this issue May 12, 2024
* added a check for window to avoid breaking node envs

addresses #992

* v0.11.22

---------

Co-authored-by: Chaitanya <yourchaitu@gmail.com>
@ChaituVR
Copy link
Member Author

Thank you @fffbbbccc it is fixed now

@ChaituVR ChaituVR linked a pull request May 12, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants