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

esm import breaks in web worker #2976

Closed
psytron opened this issue May 12, 2022 · 6 comments
Closed

esm import breaks in web worker #2976

psytron opened this issue May 12, 2022 · 6 comments
Assignees
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@psytron
Copy link

psytron commented May 12, 2022

Ethers Version

5.6.esm.min.js

Search Terms

es6 esm import web worker

Describe the Problem

importing ethers in web worker throws exceptions about missing window object

expected behavior: use ethers inside web worker to improve CPU efficiency while rendering UI
Screen Shot 2022-05-11 at 11 57 28 PM

Code Snippet

// web_worker.js
import { ethers } from './ethers-5.6.esm.min.js';

Temp work around ?

// ethers-5.6.esm.min.js
var window = self;  

Contract ABI

No response

Errors

No response

Environment

No response

Environment (Other)

No response

@psytron psytron added the investigate Under investigation and may be a bug. label May 12, 2022
@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label May 13, 2022
@ricmoo
Copy link
Member

ricmoo commented May 13, 2022

Are you sure you are on the most recent version of ethers? If so, can you use the non-minified version so you can provide a better line number? :)

@psytron
Copy link
Author

psytron commented May 14, 2022

lnum

Using: https://raw.githubusercontent.com/ethers-io/ethers.js/master/packages/ethers/dist/ethers.esm.js

@psytron
Copy link
Author

psytron commented May 20, 2022

var window = self;

Adding this on line 4909 seems to fix the issue. It imports successfully and ethers appears to be functioning normally in web workers. Hopefully something else isn't breaking or requiring separate version of ethers for non-web-worker use :)

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels May 20, 2022
@ricmoo
Copy link
Member

ricmoo commented May 20, 2022

I've confirmed this issue. Researching how to fix it now, as the dust files are generated by rollup; there is likely some config to make this play nicely with others.

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels May 21, 2022
@ricmoo
Copy link
Member

ricmoo commented May 21, 2022

This should be fixed in 5.6.7. Please try it out and let me know.

Thanks! :)

@psytron
Copy link
Author

psytron commented May 22, 2022

Confirmed imports perfectly now
ethers.version => 'ethers/5.6.7'
Excellent !! Thank You! :)

@ricmoo ricmoo closed this as completed May 26, 2022
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants