electron / packager

Customize and package your Electron app with OS-specific bundles (.app, .exe, etc.) via JS or CLI
https://npm.im/@electron/packager
BSD 2-Clause "Simplified" License
155 stars 17 forks source link

Unable to read preload script cdv-electron-preload.js #1646

Closed BenLaKnet closed 9 months ago

BenLaKnet commented 9 months ago

Preflight Checklist

Issue Details

I have this error message when I tried to package app

Unable to load preload script: /xxx/platforms/electron/Mon Glucko-mas-x64/Mon Glucko.app/Contents/Resources/app/www/cdv-electron-preload.js

I tried to modify cdv-electron-main.js, tried to modify electron-version, but nothing is running.

I used this command to package:

electron-packager ./ "Mon Glucko" --platform=mas --electron-version=28.0.0 --app-bundle-id=com.monglucko.app --overwrite --icon="icon.icns" The electron source code is based on cordova.

welcome[bot] commented 9 months ago

👋 Thanks for opening your first issue here! If you have a question about using Electron Packager, read the support docs. If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. Development and issue triage is community-driven, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

BenLaKnet commented 9 months ago

I found a solution:

const browserWindowOpts = Object.assign({}, cdvElectronSettings.browserWindow, { icon: appIcon });
    browserWindowOpts.webPreferences.nodeIntegration = true;
    //browserWindowOpts.webPreferences.preload = path.join(app.getAppPath(), 'www/cdv-electron-preload.js');
    browserWindowOpts.webPreferences.preload = path.join(__dirname, 'cdv-electron-preload.js');
    browserWindowOpts.webPreferences.contextIsolation = true;