Skip to content

fix: Support both development and production builds in Electron#326

Open
upendra512 wants to merge 1 commit intoAOSSIE-Org:mainfrom
upendra512:fix/electron-dev-build-path-284
Open

fix: Support both development and production builds in Electron#326
upendra512 wants to merge 1 commit intoAOSSIE-Org:mainfrom
upendra512:fix/electron-dev-build-path-284

Conversation

@upendra512
Copy link

Description

Fixes Issue #284 - npm run electron not working after development builds

Added intelligent path detection to support running the Electron app after both development builds (npm run build) and production packages (npm run dist).

Problem

Developers were forced to run npm run dist (full packaging) to test even small changes because npm run electron only worked with packaged builds. This made the development workflow extremely slow and painful:

Before:

  1. Make a small code change
  2. Run npm run build (✅ works)
  3. Run npm run electron (❌ fails - can't find server)
  4. Run npm run dist (😢 slow, packages entire app)
  5. Test the change

This cycle took several minutes for each iteration, making rapid development nearly impossible.

Solution

Implemented smart path detection that checks for both development and production server locations:

Path Detection Logic

  1. Development Path (checked first):

    • Location: process.cwd()/.output/server/index.mjs
    • Used after: npm run build
    • Enables: Fast iteration during development
  2. Production Path (fallback):

    • Location: app.asar.unpacked/.output/server/index.mjs
    • Used after: npm run dist
    • Preserves: Original packaging behavior
  3. Error Handling:

    • Clear messages if neither path exists
    • Instructs user to run npm run build first
    • Gracefully quits instead of hanging

Development Mode Features

When development build is detected:

  • Server Logs Visible: stdio: 'inherit' shows all server output
  • Terminal Window Shown: windowsHide: false for debugging
  • Faster Debugging: See errors and warnings immediately

When production build is detected:

  • Original Behavior Preserved: Hidden logs and terminal
  • Clean User Experience: No developer noise

Workflow Improvements

After this fix:

  1. Make a code change
  2. Run npm run build (builds in seconds)
  3. Run npm run electron (✅ works!)
  4. Test immediately
  5. Repeat

Development iteration time reduced from minutes to seconds.

Technical Details

File: electron/main.cjs

Changes made:

  • Added devPath variable for development builds
  • Added prodPath variable for production builds
  • Added isDevelopment flag to track current mode
  • Modified spawn options based on mode:
    • stdio: 'inherit' (dev) vs 'ignore' (prod)
    • windowsHide: false (dev) vs true (prod)
  • Added comprehensive error handling and logging

Lines Changed: +27/-5

Testing Scenarios

Development Mode

npm run build
npm run electron  # ✅ Now works!

Production Mode

npm run dist
# Run the packaged executable  # ✅ Still works!

Error Handling

npm run electron  # Without building first
# Shows clear error message
# Instructs to run 'npm run build'

Impact

For Contributors

  • Faster iteration: Test changes in seconds instead of minutes
  • Better debugging: See server logs during development
  • Lower barrier: No need to understand packaging process
  • Reduced frustration: Instant feedback on changes

For Project

  • More contributions: Easier development encourages participation
  • Better code quality: Faster testing enables more thorough validation
  • Improved onboarding: New contributors can iterate quickly

Backwards Compatibility

  • Production builds: Unchanged behavior (hidden logs/terminal)
  • Existing workflows: All npm run dist usage still works
  • CI/CD: No impact on automated builds

Related Issues

Closes #284

Notes

This change significantly improves the developer experience for anyone contributing to Rein. The ability to quickly test changes without full packaging is essential for productive development.

Add intelligent path detection to support running Electron app after
development builds (npm run build) in addition to production packages
(npm run dist).

Changes:
- Check for development path first: process.cwd()/.output/server/index.mjs
- Fallback to production path: app.asar.unpacked/.output/server/index.mjs
- Show clear error messages if neither path exists
- Enable server logs (stdio: inherit) in development mode
- Show terminal window in development for debugging
- Preserve original production behavior (hidden logs/terminal)

This eliminates the need to run 'npm run dist' for every small change
during development, significantly improving developer experience and
iteration speed.

Before: Developers had to package the entire app for testing
After: Developers can test with 'npm run build && npm run electron'

Fixes AOSSIE-Org#284

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2026

Warning

Rate limit exceeded

@upendra512 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2588dbc-a86a-49ee-a2e3-7f956e74274f

📥 Commits

Reviewing files that changed from the base of the PR and between 25b2382 and 98be90b.

📒 Files selected for processing (1)
  • electron/main.cjs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: npm run electron not working

2 participants