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

File uses global instead of globalThis #416

Closed
1 task done
gilbert opened this issue Apr 10, 2024 · 2 comments · Fixed by #417
Closed
1 task done

File uses global instead of globalThis #416

gilbert opened this issue Apr 10, 2024 · 2 comments · Fixed by #417

Comments

@gilbert
Copy link
Contributor

gilbert commented Apr 10, 2024

Is there an existing issue for this?

  • I have searched the existing issues

SDK version

3.0.32, but issue exists on master

Lit Network

N/A, trying to bundle package for browser

Description of the bug/issue

Can't find variable: global
../../node_modules/@lit-protocol/auth-browser/src/lib/chains/eth.js

which points to this line

Severity of the bug

Can't bundle for browser in a create-react-app

Steps To Reproduce

Using globalThis instead of global fixes the problem. The rest of the file also uses globalThis, so this would maintain consistency.

Link to code

No response

Anything else?

No response

@joshLong145
Copy link

thanks for calling this out! Nice find.

@gilbert gilbert changed the title [Team Name] <title-for-the-issue> File uses global instead of globalThis Apr 12, 2024
@gilbert
Copy link
Contributor Author

gilbert commented Apr 12, 2024

FYI the issue isn't fixed yet. The error was that global is not defined. The change in the PR...

- if (typeof global.Buffer === 'undefined') {
+ if (global && typeof global.Buffer === 'undefined') {

...still attempts to use the global variable, which will still produce the error.

The solution is to replace all usage of global with globalThis. The MDN article describes why you only need globalThis:

Unlike similar properties such as window and self [and global], globalThis is guaranteed to work in window and non-window contexts. In this way, you can access the global object in a consistent manner without having to know which environment the code is being run in.

gilbert added a commit to snowball-tools/lit-js-sdk that referenced this issue May 3, 2024
LIT-Protocol#416 (comment)

Signed-off-by: Gilbert <gilbertbgarza@gmail.com>
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.

2 participants