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.
- Press Command + Space, type
Activity Monitor, and press Enter. - In the search box in the top-right corner, enter the name of the failing application (e.g.
DiscordorSlack). - Select all matching processes (including Discord Helper, Discord Helper (Renderer), etc.).
- Click the Stop (X) button in the upper toolbar and select Force Quit.
- 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.
- Ensure the application is completely closed.
- Open Finder, click the Go menu at the top of the screen, and select Go to Folder… (or press Cmd + Shift + G).
- Type the following path and press Enter:
~/Library/Application Support - Locate the folder corresponding to your application (e.g.
discordorSlack). - Drag the folder to the Trash (or rename it to
discord.bakas a backup). - Next, press Cmd + Shift + G again and navigate to:
~/Library/Caches - Locate the application cache folder (e.g.
com.hnc.Discordorcom.tinyspeck.slackmacgap) and delete it. - 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.
- Open Terminal from Applications > Utilities.
- 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 - 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.
- Open Finder > Applications.
- Locate the affected application and drag it to the Trash.
- Navigate to
~/Library/Application Supportand delete the app folder as described in Method 2. - Reboot your Mac.
- Visit the developer’s official website, download the latest
.dmginstaller, and drag the fresh application icon into yourApplicationsdirectory.
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.
- Verify that your Mac is updated to the latest stable release via System Settings > General > Software Update.
- 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.
- 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.