feat: add exports field to package.json for ESM subpath resolution#483
Merged
Conversation
Without an exports field, Node's ESM resolver does not auto-append .js to subpath imports. Consumers with "type": "module" had to write 'electron-log/main.js' instead of 'electron-log/main' (as the README and .d.ts files imply) or hit ERR_MODULE_NOT_FOUND at production resolve time. Adding a minimal exports map mirrors the existing top-level entry files (main, renderer, preload, node) plus the root entry and package.json, keeping both 'import' and 'require' conditions to preserve CJS behavior. Existing main/browser fields are left intact for legacy resolution paths. Refs: #482
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an exports map to package.json to make the documented ESM bare subpath imports (e.g. electron-log/main) resolvable without requiring consumers to append .js, addressing ESM resolution behavior in Node/Electron tooling.
Changes:
- Added
exportsentries for the package root (".") and documented subpath entry points (./main,./renderer,./preload,./node). - Added a wildcard subpath export (
"./*": "./*") to permit arbitrary subpath access underexports.
Comments suppressed due to low confidence (1)
package.json:58
- The PR description/issue proposal mentions explicitly exporting
./package.jsonand usingimport/requireconditions for subpaths, but the actualexportsmap here adds a./*wildcard and doesn’t include an explicit./package.jsonentry. Please align the implementation with the described shape (or update the PR description) so the intended compatibility surface is unambiguous.
"./*": "./*",
"./main": {
"types": "./main.d.ts",
"default": "./main.js"
},
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Owner
|
Thank you! |
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
Adds an
exportsfield topackage.jsonso that ESM consumers can use the documented bare subpath imports (electron-log/main,electron-log/renderer,electron-log/preload,electron-log/node) without having to append.js.Closes #482.
Why
electron-log@5.4.3does not declare anexportsfield. Node's ESM resolver does not auto-append.jsfor subpath imports, so projects with"type": "module"(e.g. Electron apps bundled byelectron-viteafter Electron 28+ ESM support) currently have to writeelectron-log/main.js, contradicting the README and the shipped.d.tsfiles. Without.js, resolution fails withERR_MODULE_NOT_FOUNDonly in production bundles, which is a confusing footgun.What changed
Only
package.json:main/browserfields are left in place for legacy resolution paths.importandrequireconditions map to the same file (the package is CJS at the implementation level), so this is purely additive — no breaking change for existing CJS users../package.jsonis exported because Node's package self-reference rules become strict onceexportsis present, and downstream tooling sometimes wants to read it.Verification
Locally I
npm install'd the patched package into a fresh ESM project ("type": "module", Node 24) and reran the repro from #482:CJS continued to work for
require('electron-log'),require('electron-log/preload'),require('electron-log/node').I have not run
npm run test:fullbecause the e2e suite requires Electron and a display; happy to do so or to adjust theexportsshape if you prefer different conditions.Notes
.jsworkaround in subpath imports.