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

When launching popular Electron-based desktop applications on macOS, such as Discord, Microsoft Teams, Slack, VS Code, or Spotify, users may occasionally encounter an alarming dialogue box stating: A JavaScript error occurred in the main process. Below the banner, a lengthy stack trace usually references missing Node.js modules, unexpected token exceptions, or unhandled promise rejections originating from within the application package.

Because Electron applications run an embedded Chromium browser coupled with a Node.js runtime, this error occurs when the application’s local user configuration files, cache stores, or auto-updater manifests become corrupted. Apply the following solutions to restore normal application operation on your Mac.

Force Quit and Terminate Stray Application Processes

If an application background helper or updater daemon hung during a previous system sleep or shutdown cycle, subsequent launch attempts will fail due to locked resource databases:

  1. Press Command + Space to open Spotlight, 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 Teams).
  3. Select any running processes associated with the application, including Helper and Renderer threads.
  4. Click the Stop (X) button in the toolbar and choose Force Quit.
  5. Attempt to relaunch the software to check if the error clears.

Delete Corrupted Application Support Caches

The vast majority of JavaScript main process crashes stem from corrupted JSON profiles or IndexedDB databases stored within the user Library directory:

  1. Open Finder.
  2. Click Go in the top menu bar, hold down the Option key, and click Library (the Library folder is hidden by default).
  3. Open the Application Support folder.
  4. Locate the folder corresponding to the troubled app (for example, discord, Slack, or Microsoft Teams).
  5. Drag the entire folder to the Trash. (Note: This will reset your local app settings, requiring you to sign back in upon launch, but it will not delete your account data).
  6. Empty the Trash and launch the application again. The software will regenerate clean configuration manifests automatically.

Purge Saved Application State and Caches

macOS maintains snapshot states of applications to restore windows upon reboot. If a crash state was captured, macOS may repeatedly attempt to restore the broken execution state:

  1. In Finder, navigate back to your user Library folder.
  2. Open the Caches directory and delete the folder matching the application identifier (e.g. com.hnc.Discord).
  3. Navigate to ~/Library/Saved Application State/.
  4. Locate and delete the .savedState folder corresponding to the software.
  5. Restart your Mac to flush kernel memory caches.

Perform a Clean Reinstallation

If an automatic background update was interrupted by a power failure or sudden network disconnection, essential JavaScript libraries inside the application bundle itself may be corrupted:

  1. Open Finder and navigate to the Applications directory.
  2. Drag the problematic application to the Trash.
  3. Open ~/Library/Preferences/ and remove any plist files associated with the app (e.g. com.hnc.Discord.plist).
  4. Visit the official developer website and download the latest installer package compiled for your Mac architecture (Apple Silicon M-series or Intel).
  5. Drag the newly downloaded application into your Applications folder and launch it.

Get the best tech tips delivered straight to your inbox.

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