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

Fix usage as ES6 module #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jan-kiszka
Copy link

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#global_context, 'this' is undefined at top-level when the script is being loaded as module. And this could actually be observed while trying to use email-addresses in a Thunderbird WebExtension:

Uncaught TypeError: global is undefined
moz-extension://5efae89a-4ceb-4bb0-8179-8e3d26b9dee9/node_modules/email-addresses/lib/email-addresses.js:1095
moz-extension://5efae89a-4ceb-4bb0-8179-8e3d26b9dee9/node_modules/email-addresses/lib/email-addresses.js:1098

According to [1], 'this' is undefined at top-level when the script is
being loaded as module. And this could actually be observed while trying
to use email-addresses in a Thunderbird WebExtension:

Uncaught TypeError: global is undefined
    <anonymous> moz-extension://5efae89a-4ceb-4bb0-8179-8e3d26b9dee9/node_modules/email-addresses/lib/email-addresses.js:1095
    <anonymous> moz-extension://5efae89a-4ceb-4bb0-8179-8e3d26b9dee9/node_modules/email-addresses/lib/email-addresses.js:1098

Fix it by using globalThis when calling the anonymous function.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

Signed-off-by: Jan Kiszka <[email protected]>
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 this pull request may close these issues.

1 participant