-
Notifications
You must be signed in to change notification settings - Fork 55
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
create exports for cjs and mjs #59
base: main
Are you sure you want to change the base?
create exports for cjs and mjs #59
Conversation
Thanks for the pull request! However, I'm afraid providing a CommonJS bundle is currently out of scope. Disclaimer: This is my personal opinion and not of our team.
Can you use dynamic |
Thank you for your suggestion. However, we are using Typescript for our library and it is not possible at the moment for the Typescript compiler to distinguish between dynamic and regular import. In other words, dynamic import gets compiled to require. |
Ah, gotcha. That is a vexing problem. Allow me to think more about this. |
From the thread, it seems that TypeScript 4.7+ amended the problem with
This should prevent the compiler from erroneously transpiling dynamic |
Hi, sorry for the long-awaited answer. We are considering your suggestion concerning dynamic imports. However, this comes short when importing types, since we also use typescript in our library. We are now using a vendor submodule where we can set up node "CJS" module type in package.json, but this has its shortcomings as there can be discrepancies between the original and vendor lib and takes a toll on maintenance. We will be discussing transferring our library to ESM tomorrow. |
Ah, I see. It appears that our project itself is not ready for I've since changed my mind on the matter, though. Providing CommonJS bundles for CJS users seems worth risking the dual package hazard. I will open a separate PR that adds a CJS bundle, though I want to use conditional exports instead of the P. S. Are you building a library or an application? Does your project target Node.js, web browsers, or both? Which version of Node.js do you use? What bundler, if any? These are important information we need to decide on how to best support you. |
We have decided to switch to ESM, but CommonJS can be also useful for us. As for your questions: we are building a library which will be used for both node.js and the browser. We are using 16.3.2+ Node and for building, we use vite when bundling onto the web (we don't bundle the library itself, we bundle the web build of the app which uses it as a dependency). |
We are using CJS modules, so we created pull request to solve this issue.