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

Usage standards for CommonJS / ES Module files #71

Open
1 task done
tukib opened this issue Dec 7, 2023 · 3 comments
Open
1 task done

Usage standards for CommonJS / ES Module files #71

tukib opened this issue Dec 7, 2023 · 3 comments
Assignees

Comments

@tukib
Copy link
Member

tukib commented Dec 7, 2023

Problem

We have been using ES Module syntax (#47), but we currently use this in .js files. While the docusaurus build works due to it using babel+webpack, this is not compatible with Jest, which requires us to use either .mjs or add "type": "module" to package.json.

Using "type": "module" makes the build fail, as docusaurus emits CJS under .js and ESM under .mjs.

Context

The easiest solution is to ensure that all JS files using CommonJS syntax have the .js file extension, and those using ES Module syntax have the .mjs extension.

  • Alternatively, if it is trivial to change docusaurus' emit preference we could use .js for ESM and .cjs for CJS, allowing us to use type: module. Everything below still applies.

We should not mix CJS and ESM in a single file.

Test files should use the same extension and module syntax as the file(s) being imported.

To resolve this issue, we need to document our policy/standard for using CommonJS and ES Module files:

Another solution may be possible with additional configuration of babel or webpack, but after testing a couple options I am not confident this is easy or sound to do.

@tukib tukib added the needs triage This is a new issue that needs to be reviewed. label Dec 7, 2023
@tukib tukib changed the title Using type: module in package.json causes build to fail. consistency needed for CommonJS / ES Module files Dec 8, 2023
@seanmakesgames
Copy link
Member

What is the problem that 'having consistency' solves? (problem is listed as 'we don't have consistency' -- but what is the underlying problem)

@tukib tukib changed the title consistency needed for CommonJS / ES Module files Usage standards for CommonJS / ES Module files Dec 15, 2023
@tukib
Copy link
Member Author

tukib commented Dec 15, 2023

What is the problem that 'having consistency' solves? (problem is listed as 'we don't have consistency' -- but what is the underlying problem)

This is in reference to #47, so I've now added this to the issue description to reflect that. I've also clarified the problem & context a bit more.

@seanmakesgames seanmakesgames added low priority and removed needs triage This is a new issue that needs to be reviewed. labels Dec 18, 2023
@tukib tukib self-assigned this Dec 18, 2023
@seanmakesgames
Copy link
Member

preference for the second alternative -- we should use ESM everywhere. If it's hard, don't do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants