Title: electron-packager fails in npm workspaces monorepo · Issue #127 · kinectron/kinectron · GitHub
Open Graph Title: electron-packager fails in npm workspaces monorepo · Issue #127 · kinectron/kinectron
X Title: electron-packager fails in npm workspaces monorepo · Issue #127 · kinectron/kinectron
Description: Issue: electron-packager fails in npm workspaces monorepo Problem The npm run package script in the app/ workspace fails to run correctly when executed from either: The monorepo root: npm run package --workspace=app Inside the app direct...
Open Graph Description: Issue: electron-packager fails in npm workspaces monorepo Problem The npm run package script in the app/ workspace fails to run correctly when executed from either: The monorepo root: npm run packa...
X Description: Issue: electron-packager fails in npm workspaces monorepo Problem The npm run package script in the app/ workspace fails to run correctly when executed from either: The monorepo root: npm run packa...
Opengraph URL: https://github.com/kinectron/kinectron/issues/127
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"electron-packager fails in npm workspaces monorepo","articleBody":"# Issue: electron-packager fails in npm workspaces monorepo\n\n## Problem\n\nThe `npm run package` script in the `app/` workspace fails to run correctly when executed from either:\n- The monorepo root: `npm run package --workspace=app`\n- Inside the app directory: `cd app \u0026\u0026 npm run package`\n\nThe packaging process with `electron-packager` does not work properly in the npm workspaces environment.\n\n## Current Workaround\n\nTo successfully package the application:\n\n1. Copy the entire `app/` folder outside of the monorepo root\n2. Navigate into the copied folder\n3. Run `npm install` (this creates a local `node_modules/` in the copied folder)\n4. Run `npm run package`\n5. This successfully creates the packaged application\n\n## Technical Details\n\n### Root Cause\n\nThe issue stems from how npm workspaces manages dependencies:\n\n1. **Hoisted Dependencies**: In npm workspaces, dependencies are hoisted to the root `node_modules/` directory\n2. **No Local node_modules**: The `app/` workspace folder does not contain its own `node_modules/` directory\n3. **electron-packager Expectations**: `electron-packager` appears to search for dependencies using relative paths from the package being built\n4. **Path Resolution Failure**: When running in a workspace, `electron-packager` cannot find dependencies because they're at `../../node_modules/` instead of `./node_modules/`\n\n### Current Package Script\n\n```json\n{\n \"scripts\": {\n \"package\": \"npm run clean \u0026\u0026 electron-packager . --overwrite\"\n }\n}\n```\n\n### Workspace Structure\n\n```\nkinectron-monorepo/\n├── node_modules/ ← All dependencies hoisted here\n├── package.json ← Workspace root\n├── app/\n│ ├── package.json\n│ └── (no node_modules) ← This is the problem\n├── client/\n└── examples/\n```\n\n### What Works\n\nWhen `app/` is copied outside the monorepo:\n- `npm install` creates a local `node_modules/` in the app folder\n- `electron-packager` finds all dependencies in the expected location\n- Packaging completes successfully\n\n## Possible Solutions\n\n### Option 1: Configure electron-packager for Workspaces (Quick Fix)\n\nAdd explicit configuration to handle workspace structure:\n\n```json\n{\n \"scripts\": {\n \"package\": \"npm run clean \u0026\u0026 electron-packager . --overwrite --no-prune --ignore='^/(?!app)'\"\n }\n}\n```\n\nConsiderations:\n- `--no-prune` may include unnecessary files\n- May need to explicitly set `--ignore` patterns\n- Not guaranteed to work with hoisted dependencies\n\n### Option 2: Use Electron Forge (Recommended)\n\nMigrate from `electron-packager` to Electron Forge, which has better monorepo support:\n\n1. Install Electron Forge: `npm install --save-dev @electron-forge/cli`\n2. Initialize: `npx electron-forge import`\n3. Configure `forge.config.js` to work with workspace structure\n4. Update package script: `\"package\": \"electron-forge package\"`\n\nBenefits:\n- Better maintained and modern\n- Built-in support for monorepos\n- More configuration options\n- Better documentation\n\n### Option 3: Custom Packaging Script\n\nCreate a Node.js script that handles workspace-specific packaging:\n\n```javascript\n// scripts/package-app.js\nimport packager from 'electron-packager';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst rootDir = path.resolve(__dirname, '..');\n\npackager({\n dir: path.join(rootDir, 'app'),\n out: path.join(rootDir, 'dist'),\n overwrite: true,\n // Explicitly point to root node_modules\n electronVersion: require('electron/package.json').version,\n // ... other options\n});\n```\n\nThen update package.json:\n```json\n{\n \"scripts\": {\n \"package\": \"node scripts/package-app.js\"\n }\n}\n```\n\n### Option 4: Use electron-builder Instead\n\nReplace `electron-packager` with `electron-builder`:\n\n1. Install: `npm install --save-dev electron-builder`\n2. Add build configuration to `app/package.json`\n3. Update script: `\"package\": \"electron-builder\"`\n\n`electron-builder` has better support for complex project structures.\n\n## Recommendation\n\n**Best long-term solution**: Migrate to **Electron Forge** (Option 2)\n- Industry standard\n- Active maintenance\n- Built for modern projects\n- Good monorepo support\n- Easier auto-updates\n\n**Quick fix**: Try **Option 1** with `--no-prune` and explicit node_modules paths\n\n## Related Files\n\n- [app/package.json](app/package.json:11) - Current package script\n- [package.json](package.json) - Workspace configuration\n\n## Environment\n\n- OS: Windows (MSYS_NT-10.0-26100)\n- Node.js: (current version)\n- npm workspaces: enabled\n- electron-packager: ^17.1.2\n","author":{"url":"https://github.com/lisajamhoury","@type":"Person","name":"lisajamhoury"},"datePublished":"2025-10-09T20:51:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/127/kinectron/issues/127"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:289102f8-dbc9-e075-29ec-cbeb1d9a3ae3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 963C:4DC05:814B4E7:AD099DD:698BBCC2 |
| html-safe-nonce | ac57a0d2c7a9f7ce99025fd9bfe62485d1e3ec8b764ab3796190554108900531 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjNDOjREQzA1OjgxNEI0RTc6QUQwOTlERDo2OThCQkNDMiIsInZpc2l0b3JfaWQiOiI0MDA3MDQ0NTU3MjQxNTY0MzU0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | aa41560fed2a32032947b6da69719911817ee2eeec7318f8a1f12e474f43afcf |
| hovercard-subject-tag | issue:3500592575 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/kinectron/kinectron/127/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ac2e6b89bebb43b7327601ca75e376d520bd1da1d3d4dd9aca863ab5cb284336/kinectron/kinectron/issues/127 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ac2e6b89bebb43b7327601ca75e376d520bd1da1d3d4dd9aca863ab5cb284336/kinectron/kinectron/issues/127 |
| og:image:alt | Issue: electron-packager fails in npm workspaces monorepo Problem The npm run package script in the app/ workspace fails to run correctly when executed from either: The monorepo root: npm run packa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lisajamhoury |
| hostname | github.com |
| expected-hostname | github.com |
| None | 640eeb7b6ff4d8d106235d228c0c286e82592d4d2403227b5b2b4fc5832297a4 |
| turbo-cache-control | no-preview |
| go-import | github.com/kinectron/kinectron git https://github.com/kinectron/kinectron.git |
| octolytics-dimension-user_id | 35077404 |
| octolytics-dimension-user_login | kinectron |
| octolytics-dimension-repository_id | 67945757 |
| octolytics-dimension-repository_nwo | kinectron/kinectron |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 67945757 |
| octolytics-dimension-repository_network_root_nwo | kinectron/kinectron |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3d444f0a47beeeac94cddbb51c91ab408befe8d4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width