Documentation Index
Fetch the complete documentation index at: https://mintlify.com/electron-userland/electron-builder/llms.txt
Use this file to discover all available pages before exploring further.
Problem
When using the two package.json structure, if your app runs the main process (executed by Electron) outside the/app folder during development, you may need to load the /app dependencies manually.
The app dependencies are placed at /app/node_modules, and your main process running in a different directory will not have access to that directory by default.
Solution
Instead of duplicating the app dependencies in the developmentpackage.json, you can make the Electron main process load the app dependencies manually.
Implementation
Here’s how to load app dependencies manually in your main process:How It Works
- Detect development mode - The code checks for a
--devflag in the command line arguments - Construct path - Creates the path to
/app/node_modulesrelative to the current file - Modify module resolution - Adds the app’s
node_modulesdirectory to Node’s module search paths
Version Compatibility
- Electron 16 or lower - Use
Module.globalPaths.push(PATH_APP_NODE_MODULES) - Electron 17 or higher - Override
Module._nodeModulePathsto include the app’s node_modules path
Example Usage
You can launch your app in development mode with the--dev flag: