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

Ethers (5 and 6) expects window to be defined #3856

Closed
KillariDev opened this issue Mar 3, 2023 · 4 comments
Closed

Ethers (5 and 6) expects window to be defined #3856

KillariDev opened this issue Mar 3, 2023 · 4 comments
Assignees
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. v5 Issues regarding legacy-v5

Comments

@KillariDev
Copy link

Ethers Version

5.5.1

Search Terms

window, service worker, globalThis

Describe the Problem

When importing Ether's (ethers.esm.js) on environment (eg, service worker) that has not defined window, importing fails. This is because line 4864 is

var __awaiter = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {

I believe these checks should check typeof window !== 'undefined' instead of for window. Other alternative would be to to use globalThis and not window.

Code Snippet

import { ethers } from 'ethers.esm.js'

Contract ABI

No response

Errors

Uncaught ReferenceError: window is not defined

ethers.esm.js:4864 (anonymous function)
var __awaiter = (window && window.__awaiter) || function (thisArg, _arguments, P, generator) {

Environment

Browser (Chrome, Safari, etc)

Environment (Other)

No response

@KillariDev KillariDev added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Mar 3, 2023
@KillariDev KillariDev changed the title Ether's (5 and 6) expect window to be defined Ethers (5 and 6) expects window to be defined Mar 3, 2023
@ricmoo
Copy link
Member

ricmoo commented Mar 3, 2023

It looks like you are using an old version of ethers. Please update to the latest v5 or v6 version.

@KillariDev
Copy link
Author

Ethers v6 has the same bug in this line:

var __classPrivateFieldSet$4 = (window && window.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

@ricmoo ricmoo added the on-deck This Enhancement or Bug is currently being worked on. label Mar 6, 2023
@ricmoo
Copy link
Member

ricmoo commented Mar 7, 2023

This should be fixed in v6.1.0. Try it out and let me know! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. v5 Issues regarding legacy-v5 and removed on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6 labels Mar 7, 2023
@KillariDev
Copy link
Author

This should be fixed in v6.1.0. Try it out and let me know! :)

It works. Sorry for the late reply. Thank you! :)

Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Feb 22, 2024
@ricmoo ricmoo closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed/complete This Bug is fixed or Enhancement is complete and published. v5 Issues regarding legacy-v5
Projects
None yet
Development

No branches or pull requests

2 participants