fix: split ESM/CJS builds to fix Electron bundling issue#1441
Merged
fix: split ESM/CJS builds to fix Electron bundling issue#1441
Conversation
ESM build: unbundled with external deps (ESM consumers can import ESM) CJS build: bundled with iron-webcrypto/uint8array-extras inlined This prevents the problematic lib/node_modules/ structure that broke Electron asar packaging and pnpm symlink resolution.
Contributor
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
Splits the tsdown build configuration from a single unified config into two separate ESM and CJS builds, resolving Electron asar packaging and pnpm symlink issues.
- ESM build remains unbundled, allowing consumers to import ESM dependencies directly
- CJS build bundles ESM-only dependencies (
iron-webcrypto,uint8array-extras) for compatibility - Build order is correct: ESM cleans output directory first, then CJS adds
.cjs/.d.ctsfiles josedependency correctly excluded from bundling as it's dynamically imported viaimport()insrc/utils/jose.ts
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The build configuration changes are well-architected and solve a real problem (Electron asar packaging) without introducing new issues. The split config correctly handles ESM/CJS differences, maintains proper build ordering, and appropriately bundles only the necessary ESM-only dependencies while leaving dynamically imported packages external.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| tsdown.config.ts | 5/5 | Split build config into separate ESM (unbundled) and CJS (bundled) configurations to fix Electron asar packaging issues |
Sequence Diagram
sequenceDiagram
participant Dev as Developer
participant Build as tsdown Build
participant ESM as ESM Config
participant CJS as CJS Config
participant Output as lib/ Directory
Dev->>Build: npm run build
Note over Build,Output: Array config processed sequentially
Build->>ESM: Process first config
ESM->>Output: clean: true (clear directory)
ESM->>Output: Generate .js files (unbundled)
ESM->>Output: Generate .d.ts files
Note over ESM,Output: Dependencies external<br/>(iron-webcrypto, jose)
Build->>CJS: Process second config
Note over CJS: clean: false (preserve ESM files)
CJS->>CJS: Bundle iron-webcrypto<br/>and uint8array-extras
CJS->>Output: Generate .cjs files (bundled)
CJS->>Output: Generate .d.cts files
Note over CJS,Output: ESM-only deps inlined<br/>jose remains external
Output-->>Dev: Build complete<br/>Both formats in lib/
dandorman
approved these changes
Jan 9, 2026
nicknisi
added a commit
that referenced
this pull request
Jan 9, 2026
## Summary - Splits tsdown build config into separate ESM and CJS configurations - ESM: unbundled with external deps (ESM consumers import ESM deps directly) - CJS: bundled with `iron-webcrypto` and `uint8array-extras` inlined ## Problem Previous single config with `noExternal` created `lib/node_modules/` structure that broke Electron asar packaging and pnpm symlink resolution. ## Why CJS inlining is required `iron-webcrypto` and `uint8array-extras` are ESM-only packages—they don't ship CJS builds. CJS code can't `require()` ESM modules, so these deps must be inlined/bundled into the CJS output for compatibility.
nicknisi
added a commit
that referenced
this pull request
Jan 12, 2026
## Summary - Splits tsdown build config into separate ESM and CJS configurations - ESM: unbundled with external deps (ESM consumers import ESM deps directly) - CJS: bundled with `iron-webcrypto` and `uint8array-extras` inlined ## Problem Previous single config with `noExternal` created `lib/node_modules/` structure that broke Electron asar packaging and pnpm symlink resolution. ## Why CJS inlining is required `iron-webcrypto` and `uint8array-extras` are ESM-only packages—they don't ship CJS builds. CJS code can't `require()` ESM modules, so these deps must be inlined/bundled into the CJS output for compatibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
iron-webcryptoanduint8array-extrasinlinedProblem
Previous single config with
noExternalcreatedlib/node_modules/structure that broke Electron asar packaging and pnpm symlink resolution.Why CJS inlining is required
iron-webcryptoanduint8array-extrasare ESM-only packages—they don't ship CJS builds. CJS code can'trequire()ESM modules, so these deps must be inlined/bundled into the CJS output for compatibility.