How to Fix ‘A JavaScript Error Occurred in the Main Process’ on Mac

Launching modern desktop applications like Discord, Slack, Visual Studio Code, Spotify, or Microsoft Teams on macOS only to be halted by a dialog box displaying “A JavaScript error occurred in the main process. Uncaught Exception: Error: Cannot find module…” prevents the program from loading its graphical interface.

These applications are built on the Electron framework, which uses an embedded Node.js runtime and Chromium engine. The “main process” error indicates that Node.js encountered a fatal uncaught exception during startup—typically because local configuration files inside ~/Library/Application Support/ were corrupted during an interrupted automatic update, file permissions became locked, or orphaned background processes hold database locks.

Failure Point Technical Breakdown Targeted Solution
Corrupted Electron Application Cache Interrupted auto-update left broken JavaScript bundles in Application Support Delete local App Support and Caches directories
Orphaned Process Locks Previous instance crashed without releasing SQLite / LevelDB database locks Force kill all application child processes via Activity Monitor
Corrupted Preferences Plist Preferences plist file contains malformed XML properties Purge ~/Library/Preferences/[App].plist
Damaged Application Bundle Binary codesigning or app assets damaged in /Applications Reinstall application cleanly from official dmg

Method 1: Force Quit All Orphaned Background Processes

Electron applications spawn multiple helper processes (Renderer, GPU, Crashpad). If a previous session terminated abnormally, an orphaned background process may retain exclusive file locks on local databases.

  1. Press Command + Space, type Activity Monitor, and press Enter.
  2. In the search box in the top-right corner, enter the name of the failing application (e.g. Discord or Slack).
  3. Select all matching processes (including Discord Helper, Discord Helper (Renderer), etc.).
  4. Click the Stop (X) button in the upper toolbar and select Force Quit.
  5. Once all processes have vanished from the list, attempt opening the application normally.

Method 2: Clear Application Support and Cache Directories

Electron stores user profiles, dynamic update modules, and local runtime scripts in your user Library. Deleting these folders forces the application to redownload fresh, uncorrupted runtime bundles.

  1. Ensure the application is completely closed.
  2. Open Finder, click the Go menu at the top of the screen, and select Go to Folder… (or press Cmd + Shift + G).
  3. Type the following path and press Enter:
    ~/Library/Application Support
  4. Locate the folder corresponding to your application (e.g. discord or Slack).
  5. Drag the folder to the Trash (or rename it to discord.bak as a backup).
  6. Next, press Cmd + Shift + G again and navigate to:
    ~/Library/Caches
  7. Locate the application cache folder (e.g. com.hnc.Discord or com.tinyspeck.slackmacgap) and delete it.
  8. Empty the Trash and launch the application. It will recreate fresh default settings.

Method 3: Reset App Preferences via Terminal

If corrupted macOS preferences retain broken startup parameters, flushing the application’s domain via Terminal restores baseline properties.

  1. Open Terminal from Applications > Utilities.
  2. Execute the defaults delete command for the problematic app:
    (For Discord): defaults delete com.hnc.Discord
    (For Slack): defaults delete com.tinyspeck.slackmacgap
    (For VS Code): defaults delete com.microsoft.VSCode
  3. Restart your Mac to ensure cfprefsd flushes memory caches.

Method 4: Perform a Clean Reinstallation of the Application

If the error references a missing internal core module (e.g. Cannot find module 'electron'), core application assets inside the macOS /Applications bundle are damaged.

  1. Open Finder > Applications.
  2. Locate the affected application and drag it to the Trash.
  3. Navigate to ~/Library/Application Support and delete the app folder as described in Method 2.
  4. Reboot your Mac.
  5. Visit the developer’s official website, download the latest .dmg installer, and drag the fresh application icon into your Applications directory.

Method 5: Check Node.js and macOS Version Compatibility

Older Electron framework versions packaged with legacy desktop tools may encounter compatibility issues with recent macOS Sequoia or Sonoma kernel security changes.

  1. Verify that your Mac is updated to the latest stable release via System Settings > General > Software Update.
  2. Ensure you downloaded the correct binary architecture for your Mac hardware:
    • Apple Silicon (M1/M2/M3/M4): Download the Apple Silicon / ARM64 build.
    • Intel Macs: Download the Intel / x86_64 build.
  3. Running native Apple Silicon builds eliminates Rosetta 2 translation exceptions that frequently manifest as JavaScript runtime crashes.

Safeguarding Your Local Data

Clearing ~/Library/Application Support/ removes local temporary session files and requires you to sign back into your account. However, because modern applications like Discord, Slack, and VS Code synchronize your message history, servers, and settings with cloud databases, no personal account data or cloud chat logs are lost during this troubleshooting process.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.