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

feat: Add support for ESModules and CommonJS at the same time #517

Closed
GuilhermeWerner opened this issue Jan 27, 2024 · 3 comments · Fixed by #519
Closed

feat: Add support for ESModules and CommonJS at the same time #517

GuilhermeWerner opened this issue Jan 27, 2024 · 3 comments · Fixed by #519

Comments

@GuilhermeWerner
Copy link
Contributor

What is this feature about?
Since gamedig is a library, it would be more interesting to allow users who use it to choose within the scope of their projects whether to use ESModules or CommonJS.

Additional context/references
Many people are having problems using version 5.0 because their projects use CommonJS require("gamedig"). Using a bundler like esbuild, it is possible to maintain the same code base and support both module methods.

I did some testing with esbuild, where the library is transpiled to ESModule and CommonJS with a script.

Just keep in mind that this adds an extra step to the lib, requiring the build script to be run before publishing, for example. But at the same time it removes the obligation to use ESModules.

@dgibbs64
Copy link
Contributor

I came across this issue and took me a while to convert it as I am a nodejs newbie. But got there in the end. But this is a code breaking thing for projects that already use gamedig. If it is possible to upgrade to 5 without having to refactor that would be idea.

@Mululu
Copy link

Mululu commented Jan 27, 2024

Simply rewrite the projects from CommonJS to ESModules. Has many advantages and is now not that difficult. There will also be more and more ESModules in the future.

@CosminPerRam
Copy link
Member

Thanks bunch, could you make a PR?

Simply rewrite the projects from CommonJS to ESModules. Has many advantages and is now not that difficult. There will also be more and more ESModules in the future.

It indeed is not that difficult and yeah, it will be more and more in the future, but not all projects are that easy to rewrite (you wouldn't move to esm if you got a huge cjs project) and as @dgibbs64 said, it's quite confusing for beginners and it is a breaking change that we could easily fix for pretty much nothing.

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

Successfully merging a pull request may close this issue.

4 participants