[PR #1] Fix ESM/CJS conflict: rename electron/*.js to *.cjs #1

Open
opened 2026-04-08 13:45:39 +00:00 by thisisjaymehta · 0 comments

📋 Pull Request Information

Original PR: https://github.com/thisisjaymehta/bentopdf/pull/1
Author: @Copilot
Created: 2/10/2026
Status: 🔄 Open

Base: mainHead: copilot/convert-app-to-electron


📝 Commits (4)

  • b67dcff Initial plan
  • 1d1ed1d Add Electron wrapper with PDF file association support for Windows
  • a9c9576 Address code review feedback: cross-platform dev runner, IPC cleanup, simplified buffer
  • 70445c9 Rename electron/*.js to *.cjs to fix ESM/CJS conflict

📊 Changes

8 files changed (+318 additions, -3 deletions)

View changed files

📝 .gitignore (+4 -1)
electron/dev-runner.cjs (+55 -0)
electron/main.cjs (+139 -0)
electron/preload.cjs (+23 -0)
📝 eslint.config.mjs (+1 -1)
📝 package.json (+62 -1)
📝 src/js/logic/edit-pdf-page.ts (+25 -0)
src/types/electron.d.ts (+9 -0)

📄 Description

Description

package.json declares "type": "module", causing Node.js to treat .js files as ESM. The Electron files use CommonJS require(), resulting in:

ReferenceError: require is not defined in ES module scope

Renamed all Electron files to .cjs and updated references:

  • electron/main.jselectron/main.cjs (also updated internal preload.jspreload.cjs path)
  • electron/preload.jselectron/preload.cjs
  • electron/dev-runner.jselectron/dev-runner.cjs
  • package.json: updated "main", electron:dev script, and build.files exclusion

Type of change

  • Bug fix (non-breaking change which fixes an issue)

🧪 How Has This Been Tested?

Checklist:

  • Verified output manually

Expected Results:

  • node electron/dev-runner.cjs parses without ESM errors; all three .cjs files pass node -c syntax check.

Actual Results:

  • All files pass syntax validation. No remaining .js references to electron files in the codebase.

Checklist:

  • I have signed the Contributor License Agreement (CLA) or my organization has signed the Corporate CLA
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
Original prompt

Convert this app to electron app, so I can install it in windows and then assosicate it as default pdf viewer so it opens all my pdfs in bentopdf's edit pdf tool when I double click the pdfs on windows


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/thisisjaymehta/bentopdf/pull/1 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 2/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `copilot/convert-app-to-electron` --- ### 📝 Commits (4) - [`b67dcff`](https://github.com/thisisjaymehta/bentopdf/commit/b67dcffeaaf483839d1563b10985e8da8e0edcfb) Initial plan - [`1d1ed1d`](https://github.com/thisisjaymehta/bentopdf/commit/1d1ed1d7da651e90c340bb2a8198b9d460bc7531) Add Electron wrapper with PDF file association support for Windows - [`a9c9576`](https://github.com/thisisjaymehta/bentopdf/commit/a9c9576cecd1cdc9f5fa2e4122037db838f176cc) Address code review feedback: cross-platform dev runner, IPC cleanup, simplified buffer - [`70445c9`](https://github.com/thisisjaymehta/bentopdf/commit/70445c94777b0996c38b8db3325df2ff6c34647b) Rename electron/*.js to *.cjs to fix ESM/CJS conflict ### 📊 Changes **8 files changed** (+318 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+4 -1) ➕ `electron/dev-runner.cjs` (+55 -0) ➕ `electron/main.cjs` (+139 -0) ➕ `electron/preload.cjs` (+23 -0) 📝 `eslint.config.mjs` (+1 -1) 📝 `package.json` (+62 -1) 📝 `src/js/logic/edit-pdf-page.ts` (+25 -0) ➕ `src/types/electron.d.ts` (+9 -0) </details> ### 📄 Description ### Description `package.json` declares `"type": "module"`, causing Node.js to treat `.js` files as ESM. The Electron files use CommonJS `require()`, resulting in: ``` ReferenceError: require is not defined in ES module scope ``` Renamed all Electron files to `.cjs` and updated references: - `electron/main.js` → `electron/main.cjs` (also updated internal `preload.js` → `preload.cjs` path) - `electron/preload.js` → `electron/preload.cjs` - `electron/dev-runner.js` → `electron/dev-runner.cjs` - `package.json`: updated `"main"`, `electron:dev` script, and `build.files` exclusion ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) ### 🧪 How Has This Been Tested? **Checklist:** - [x] Verified output manually **Expected Results:** - `node electron/dev-runner.cjs` parses without ESM errors; all three `.cjs` files pass `node -c` syntax check. **Actual Results:** - All files pass syntax validation. No remaining `.js` references to electron files in the codebase. ### Checklist: - [ ] I have signed the [Contributor License Agreement (CLA)](ICLA.md) or my organization has signed the [Corporate CLA](CCLA.md) - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Convert this app to electron app, so I can install it in windows and then assosicate it as default pdf viewer so it opens all my pdfs in bentopdf's edit pdf tool when I double click the pdfs on windows </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
thisisjaymehta/bentopdf#1
No description provided.