Replies: 1 comment 3 replies
-
Keep in mind, zx relies on external deps, some of them are distributed as esm modules only. These libdefs cannot be used in |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to import zx from a cjs file (sorry 😔), but it only ships ESM declarations files, so TypeScript errors upon import. Here's the attw report, which agrees that zx is masquerading as ESM-only instead of dual.
Unfortunately, the TS team feel's it's not tsc's place to rewrite module syntax anymore, and hasn't had plans for extending dual packaging for a while, although it might still happen someday (though with
require(esm)
, it's probably a lesser concern). I'd happy to rewrite your build scripts to fix this, but my Google account doesn't let me use sign in with Google for arbitrary apps, so I'm unable to sign the CLA. I'd be happy to review a PR or give recommendations, I just can't hit the button.Personally, I'd recommend tsdown as a good, modern bundler. It's new, so it's not perfect, but I've found it less buggy than what tsup outputs (both requirenode18
, but can compile down). tsup and tsdown have similar configuration, here's what I've found works best for packages:You'll want to ensure you have
["esm", "cjs"]
specified forformat
(dual emit),target
set tonode12
(based on your engines),clean
set totrue
,platform
set tonode
,skipNodeModulesBundle
set totrue
(very important!),shims
set totrue
(optional, enable only if needed),dts
set totrue
(for tsup) or{ transformer: 'oxc', autoAddExts: true, sourceMap: true }
(for tsdown). If you want sourcemaps, considersourcemap: true
. For tsdown, also consider enablingunused: { level: 'error' }
to warn on extraneous dependencies not used in the build.I take most of that back. Y'all try to keep the package size down by using ESM wrappers of a CJS build, which is commendable. However, ESM can import CJS. Is there a reason to do the "fake" dual-emit? I also know
require(esm)
has changed some of the recommendations around using these wrapper scripts, though I don't know what specifically.Beta Was this translation helpful? Give feedback.
All reactions