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 Reference Error for module.exports in browser environment #4229

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

BeNikk
Copy link
Contributor

@BeNikk BeNikk commented Jan 5, 2025

Description

Fixes #4228
This PR addresses a ReferenceError that occurred in browser environments due to the usage of module.exports without checking for its existence. The issue arises because module.exports is specific to Node.js/CommonJS environments and is not defined in browsers.

Solution

The fix introduces a conditional check to ensure module.exports is only assigned when the module object is defined (i.e., in Node.js/CommonJS environments). In browser environments, the export does nothing, avoiding the ReferenceError.
This solution works because before introducing the tests in musicblocks repository, we were not exporting any module, so the solution does not break anything.
Screenshot from 2025-01-05 18-50-27

Testing

The code changes make sure that all the tests still run fine.
Screenshot from 2025-01-05 19-19-36

Browser error

The browser does not throw any reference error now
Screenshot from 2025-01-05 19-12-37

@BeNikk
Copy link
Contributor Author

BeNikk commented Jan 5, 2025

@walterbender I think this can be a fix for all the reference errors, might be a simple solution but solves the issue.

@walterbender walterbender merged commit b020cb8 into sugarlabs:master Jan 5, 2025
4 checks passed
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.

module.exports ReferenceError in Browser Environment
2 participants