Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Electron-Builder - Cannot find CommandCam.exe #59

Open
pilotkid opened this issue Oct 23, 2021 · 1 comment
Open

[Windows] Electron-Builder - Cannot find CommandCam.exe #59

pilotkid opened this issue Oct 23, 2021 · 1 comment

Comments

@pilotkid
Copy link

pilotkid commented Oct 23, 2021

On windows, after packaged with electron builder I get the error

{
  cmd: "\"C:\\Users\\kp\\AppData\\Local\\Programs\\kiosk\\resources\\app.asar\\node_modules\\node- 
  webcam\\src\\bindings\\CommandCam\\CommandCam.exe\"   /filename test_picture.jpg"
  code: 1
  killed: false
  signal: null
}
@pilotkid
Copy link
Author

pilotkid commented Oct 23, 2021

Inside your builder configuration add nodeIntegration, externals, and your nodeModulesPath.

nodeIntegration: true,
externals: ['node-webcam'],
nodeModulesPath: ['node_modules'],

Then you can add a hook to onNodeModulesFile to rewrite app.asar to app.asar.unpacked

//Apply patch to fix electron-builder issue
onNodeModuleFile(file) {
    if (!file.includes('node-webcam')) return;
    if (file.includes('\\node-webcam\\src\\webcams\\WindowsWebcam.js')) {
        let str = fs.readFileSync(file, 'utf-8');
        str = str.replace(
            'WindowsWebcam.prototype.generateSh',
            `WindowsWebcam.prototype.bin = WindowsWebcam.prototype.bin.includes('.asar.unpacked') ? WindowsWebcam.prototype.bin : WindowsWebcam.prototype.bin.replace('app.asar', 'app.asar.unpacked').replace(/.unpacked.unpacked/g, '.unpacked');\r\nWindowsWebcam.prototype.generateSh`
        );
        fs.writeFileSync(file, str, 'utf-8');
        console.log(
            '✔️Applied patch to node-webcam file ""./node_modules/src/webcams/WindowsWebcam.js'
        );
    }
}

All put together (in my case in vue.config.js):

pluginOptions: {
    electronBuilder: {
        nodeIntegration: true,
        externals: ['pdf-to-printer', 'node-webcam'],
        nodeModulesPath: ['node_modules'],
        builderOptions: {
            //Apply patch to fix electron-builder issue
            onNodeModuleFile(file) {
                if (!file.includes('node-webcam')) return;
                if (file.includes('\\node-webcam\\src\\webcams\\WindowsWebcam.js')) {
                    let str = fs.readFileSync(file, 'utf-8');
                    str = str.replace(
                        'WindowsWebcam.prototype.generateSh',
                        `WindowsWebcam.prototype.bin = WindowsWebcam.prototype.bin.includes('.asar.unpacked') ? WindowsWebcam.prototype.bin : WindowsWebcam.prototype.bin.replace('app.asar', 'app.asar.unpacked').replace(/.unpacked.unpacked/g, '.unpacked');\r\nWindowsWebcam.prototype.generateSh`
                    );
                    fs.writeFileSync(file, str, 'utf-8');
                    console.log(
                        '✔️Applied patch to node-webcam file "./node_modules/src/webcams/WindowsWebcam.js"'
                    );
                }
            }
        }
    }
}
Created in Q/A style incase anyone else runs across this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant