-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Let's assume that I'm creating a new package and I want to:
- Develop and publish without a transpiler, as ESM modules.
- Allow transpiler users to depend upon my package.
If the consumer is using a transpiler, then import declarations will be transformed into require calls. When the consumer requires my package they will get an error because I don't have an "index.js" or a CJS main field.
To fix this, I create a CJS entry point into my package (say an "index.js" file).
Inside of that "index.js" file, I want to pull in my package code and expose it using module.exports, so I try this:
module.exports = import("./default.js");But import() returns a Promise, so this actually doesn't work.
There doesn't appear to be a way for me to pull in my module code and expose that module to require.
So my only option is to publish both CJS and ESM versions of each module in my package. I need to use a transpiler. But now I have two copies of my codebase to support, which is bad. I might just as well only publish the CJS version for consumers to use.
But now I'm right back to the current situation where I code in ESM and then transpile down to CJS.
It appears that as long as there is no way to synchronously load ESM modules from CJS modules, we are stuck and the ecosystem cannot move forward.
This seems pretty bad for the ecosystem.
Thoughts?