Reputation: 110
Electron app was initialized using electron-forge webpack template and everything works perfectly for macOs. While running the dev version using electron-forge start the app loads perfectly on windows. Once the app is packaged for windows using electron-forge make the build completes successfully. But while running the packaged app Cannot find module X is thrown. The folder ./out/app/resources/app/node_modules is empty. Also the package.json ./out/app/resources/app/package.json looks as follows.
"name": "my-app",
"productName": "my-app",
"version": "1.0.0",
"description": "My Electron application description",
"main": ".webpack/main",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "",
"email": ""
},
"license": "MIT",
"config": {},
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {},
"peerDependencies": {}
}
None of the dependencies in the source package.json made it to the packaged app.
Upvotes: 10
Views: 2875
Reputation: 101
I found the issue in the Webpack plugin.
Look at
It's just ignoring everything that is not .webpack.
So you have two options:
https://www.electronforge.io/config/configuration#electron-packager-config
packageAfterCopy: async (_, appResources) => {
if(appResources == null)
throw new Error(`Unknown platform ${options.platform}`);
const srcNodeModules = path.join(__dirname, 'node_modules');
const destNodeModules = path.join(appResources, 'node_modules');
fs.cpSync( srcNodeModules, destNodeModules, {recursive: true});
}
Upvotes: 1
Reputation: 11640
Try this
cd "my-app"
:: install dependency into your node_modules and update your package.json
npm install your-dependency --save-prod
npm run make
Upvotes: -3