Working dual CJS/ESM exports for sdk-core and sdk. Key points:
Do not use type in the package's package.json since it is copied into the build-specific package.json for each build type
Only use import and require in the exports field of package.json.
The types option cannot be used for dual CJS/ESM exports since it refers to a single output type and does not apply to both. Instead, by not including it, the resolution algorithm correctly implicitly infers which types to use.
I believe the default would be valid. I left it out to avoid a fallback being hit that we didn't realize was happening.
In theory, it does not matter which build dir the subpath imports option points to ("./dist/cjs/*" or "./dist/esm/*"). However, for out way of doing dual packages, it must point to the one that is built first, or else the build will not have the context of the other one and will fail at the build step.
Working dual CJS/ESM exports for
sdk-core
andsdk
. Key points:type
in the package'spackage.json
since it is copied into the build-specificpackage.json
for each build typeimport
andrequire
in theexports
field ofpackage.json
.types
option cannot be used for dual CJS/ESM exports since it refers to a single output type and does not apply to both. Instead, by not including it, the resolution algorithm correctly implicitly infers whichtypes
to use.default
would be valid. I left it out to avoid a fallback being hit that we didn't realize was happening."./dist/cjs/*"
or"./dist/esm/*"
). However, for out way of doing dual packages, it must point to the one that is built first, or else the build will not have the context of the other one and will fail at the build step.