Whatsapp web js not working with electronjs - electron

I make a project in electronJS with whatsapp-web.js. When i debug with npm start it works properly.
but when I build with electron and install the (.exe) file the project don't works. It seems the Puppeteer not running. How can I solve the problem?
NB: I am using electron-builder for build the application for Windows.
{
"name": "testapp",
"version": "1.0.0",
"description": "testapp",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-builder"
},
"build": {
"appId": "com.testapp.test",
"productName": "testapp",
"target": "NSIS",
"nsis" : {
"oneClick" : true,
"allowToChangeInstallationDirectory" : false
}
},
"author": "Udayan Basak",
"license": "ISC",
"devDependencies": {
"electron": "^15.3.1",
"electron-builder": "^22.14.5"
},
"dependencies": {
"whatsapp-web.js": "^1.15.2"
}
}
This is my package.json data.
[Again: full project working fine in development mode. It causes error in production lavel.]
const { Client } = require('whatsapp-web.js');
const {app, BrowserWindow, ipcMain, ipcRenderer } = require('electron')
const client = new Client();
client.on('qr', (qr) => {
win.webContents.send("qrcode", qr)
});
client.on('ready', () => {
win.webContents.send("ready", "ready")
})

Related

electron-updater not detecting any updates

i am making an app using electron
i already did everything regarding auto-updating the app
but its not detecting the new release (1.0.1) when opened, although i released it using electron-builder.
i did commit and checked everything
here is my code:
main.js:
function createWindow () {
// Create the browser mainWindow.
mainWindow = new BrowserWindow({
useContentSize: true,
show: false,
title: "My app",
webPreferences: {
preload: path.join(__dirname, './preload.js'),
plugins: true,
nodeIntegration: false,
webSecurity: false
}
})
registerKeys()
Menu.setApplicationMenu(createMenu());
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.once('ready-to-show', () => {
autoUpdater.checkForUpdatesAndNotify();
});
};
autoUpdater.on('update-available', (updateInfo) => {
dialog.showMessageBox({
type: "info",
buttons: ["Ok"],
title: "Update Available",
message: "There is a new version available (v" + updateInfo.version + "). It will be installed when the app closes."
});
}
);
ipcMain.on('restart_app', () => {
autoUpdater.quitAndInstall();
});
package.json:
"name": "my-app",
"version": "1.0.0",
"description": "my app",
"productName": "My app",
"main": "main.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder",
"build": "electron-builder build --win --publish never",
"deploy": "electron-builder build --win --publish always"
},
"repository": "https://github.com/mygithub/myrepo",
"build": {
"publish": [
{
"provider": "github",
"owner": "mygithub",
"repo": "myrepo"
}

How to build window electron executable program with babel

Actually I can build to use electron --trace-warnings -r #babel/register . and with #babel
electron-builder --windows nsis:ia32 command is success as a result
but i execute that, it occur error.
A JavaScript eror occured in the main process
C:\dev\electron\SomeDirectoryPath123123\index.js:1
import {app, BrowserWindow} from "electron";
^^^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFuntion (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
...etc...
please help me..
.babelrc
{
"presets": ["#babel/preset-env"]
}
package.json
{
"name": "test app",
"version": "1.0.0",
"description": "helpp me",
"main": "index.js",
"scripts": {
"manual-run": "electron --trace-warnings -r #babel/register .",
"build-package": "electron-builder --windows nsis:ia32"
},
"author": "nother",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.18.5",
"#babel/node": "^7.18.5",
"#babel/preset-env": "^7.18.2",
"#babel/register": "^7.17.7",
"electron": "^19.0.4",
"electron-builder": "^23.0.3"
},
"dependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.18.5",
"#babel/node": "^7.18.5",
"#babel/preset-env": "^7.18.2",
"#babel/register": "^7.17.7",
"elasticsearch": "^16.7.3",
"express": "^4.18.1",
"mongodb": "^4.7.0",
"node-fetch": "^2.6.7",
"sqlite3": "^5.0.8"
},
"build": {
"appId": "test-electron-app",
"productName": "hello!",
"buildDependenciesFromSource": false,
"asar": true,
"files": [
"dist/**/*",
"package.json",
"index.js"
],
"win": {
"target": "nsis"
},
"nsis": {
"oneClick": false
},
"directories": {
"buildResources": "./build/",
"output": "./distout/"
}
}
}

how to build electron app for windows in ubuntu using electron builder

I have created an electron app .Using electron-builder I created appImage in linux.I want build app for windows in linux .But it is throwing wine required error .please help to resolve this issue.
this is package.json
"name": "Gamer",
"version": "1.0.0",
"main": "main.js",
"repository": "https://github.com/XYX/GAME",
"dependencies": {
"#agm/core": "^1.0.0-beta.5",
...
"electron-builder-squirrel-windows": "^22.1.0",
"electron-packager": "^14.1.0",
"electron-reload": "^1.5.0",
"electron-store": "^5.1.0",
},
"devDependencies": {
...
"electron": "^7.1.1",
"electron-builder": "^22.1.0",
"electron-prebuilt": "^1.4.13",
"electron-updater": "^4.2.0",
...
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"start:electron": "ng build --base-href ./ && electron .",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build": "ng build --prod && electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"build:Win": "electron-builder --win",
"ship": "build",
"electron-packager": "electron-packager ./ --all."
},
"peerDependencies": {
"#angular/animations": "^7.2.15",
"#angular/cdk": "^7.3.7",
"#angular/material": "^7.3.7"
},
"author": "",
"license": "ISC",
"build": {
"appId": "com.electron.coxGamer",
"compression": "normal",
"extends": null,
"files": [
"*.js",
"build",
"dist"
],
"mac": {
"target": "zip"
},
"linux": {
"target": [
"AppImage",
"zip"
]
},
"win": {
"target": "NSIS"
},
"publish": {
"provider": "github",
"repo": "https://github.com/XYX/GAME",
"owner": "XYX"
}
}
}
Even the electron-updater throwing error for dev-update.yml not found.and also app-icon is not setting
const { app, BrowserWindow, Menu,ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const { autoUpdater } = require("electron-updater");
Menu.setApplicationMenu(null);
let mainWindow;
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1200,
height: 900
});
mainWindow.setMenuBarVisibility(false);
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
protocol: 'file:',
slashes: true
}));
mainWindow.on('closed', () => {
mainWindow = null;
});
};
autoUpdater.on('update-downloaded', (info) => {
win.webContents.send('updateReady')
});
app.on('ready', () => {
createWindow();
autoUpdater.checkForUpdates();
});
ipcMain.on("quitAndInstall", (event, arg) => {
autoUpdater.quitAndInstall();
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
Here is how I managed to build windows app from mac/linux. Maybe this can help you #Krazy.
First off all, I'm using the docker version of electron-builder
And then, here are the steps
1- Install electron builder dev in your project
npm install electron-builder —save-dev
2- In package.json add this to script
"dist": "electron-builder"
3- Launch Docker
4- In terminal, run
docker run --rm -ti \
--env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \
--env ELECTRON_CACHE="/root/.cache/electron" \
--env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \
-v ${PWD}:/project \
-v ${PWD##*/}-node-modules:/project/node_modules \
-v ~/.cache/electron:/root/.cache/electron \
-v ~/.cache/electron-builder:/root/.cache/electron-builder \
electronuserland/builder:wine
5- cd into your project
6- type
yarn && yarn dist -w
This is how I build my first windows app in Linux.
1- Install electron builder dev in your project
npm install electron-builder
2- Create a builder.js file your should look like this.
const builder = require("electron-builder")
const Platform = builder.Platform
// Promise is returned
builder.build({
targets: Platform.WINDOWS.createTarget(),
config: {
'win': {
'files': [
// All your files you are using
'main.js',
],
'compression': 'store',
'asar': false
}
}
})
.then(() => {
// handle result
})
.catch((error) => {
// handle error
})
3- Launch your app.

error showing while creating a debian file from electronjs project

I am getting the below error while making deb file of electronjs
Error: could not find the Electron app binary at "dist/app-linux-x64/koriwallet". You may need to re-bundle the app using Electron Packager's "executableName" option.
My package.json file is
{
"name": "wallet",
"version": "1.0.0",
"description": "wallet",
"main": "src/main.js",
"scripts": {
"start": "electron .",
"build": "electron-packager . myapp",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"deb64": "electron-installer-debian --src dist/app-linux-x64/ --dest dist/installers/ --arch amd64"
},
"author": "wallet",
"license": "ISC",
"devDependencies": {
"asar": "^2.0.1",
"electron": "^5.0.6",
"electron-builder": "^21.1.1",
"electron-installer-debian": "^2.0.0",
"electron-packager": "^14.0.2"
},
"electronPackagerConfig": {
"packageManager": "npm",
"executableName": "kori"
},
"build": {
"appId": "wallet",
"linux": {
"category": "wallet"
}
},
"dependencies": {
"cookies": "^0.7.3",
"crypto": "^1.0.1",
"dpkg": "^1.0.0",
"jquery": "^3.4.1",
"jstorage": "^0.4.8"
}
}
My 2 cents. I'm making an Fedora 30 rpm and got:
An unhandled error has occurred inside Forge:
An error occured while making for target: rpm
could not find the Electron app binary at "/home/ajm/Documents/Projects/sunstealer.ets/out/sunstealer.ets product-linux-x64/sunstealer.ets". You may need to re-bundle the app using Electron Packager's "executableName" option.
Error: could not find the Electron app binary at "/home/ajm/Documents/Projects/sunstealer.ets/out/sunstealer.ets product-linux-x64/sunstealer.ets". You may need to re-bundle the app using Electron Packager's "executableName" option.
at error.wrapError (/home/ajm/Documents/Projects/sunstealer.ets/node_modules/electron-installer-common/src/installer.js:145:15)
Fix was update package.json from
"name": "sunstealer.ets",
"productName": "sunstealer.ets product",
to:
"name": "sunstealer.ets",
"productName": "sunstealer.ets",
i.e. same value. Then npm run make with:
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"certificateFile": "./certs/adam_mauger.pfx",
"certificatePassword": "REDACTED"
}
},
{
"name": "#electron-forge/maker-dmg",
"config": {
"format": "ULFO"
}
},
{
"name": "#electron-forge/maker-rpm",
"config": {
}
},
created sunstealer.ets-1.0.0-1.x86_64.rpm. Hope that helps.
my 5 cents)
so, launch npm from root folder. there exist node_modules.
app stored in root/src. there exist node_modules.
and in root and in root/src have package.json
check root/src/package.json file. maybe there parameter "name" have default value in lowercase

Webpack - Can't resolve jquery

I'm new to webpack and I'm actually stucked. I read some articles about webpack and so started trying it on a project (just on third part libraries). I have created my entry-point.js:
require('angular');
require('angular-bootstrap');
require('angular-file-upload');
require('angular-local-storage');
require('angular-ui-grid');
require('angular-ui-router');
require('ng-idle');
require('bootstrap');
require('jquery');
and the webpack.config.js:
module.exports = {
entry : './entry-point.js',
output : {
path : __dirname + "/dist",
filename : 'vendor.js'
},
resolve : {
modules : [ 'bower_components' ]
}
};
but when I launch the 'npm start' I get the following error:
Module not found: Error: Can't resolve 'jquery' in
'D:\Documents\Sviluppo\Eclipse\Workspace\SCARICO-TeamcenterEasyApp\target\TeamcenterEasyApp-0.0.1'
resolve 'jquery' in
'D:\Documents\Sviluppo\Eclipse\Workspace\SCARICO-TeamcenterEasyApp\target\TeamcenterEasyApp-0.0.1'
Obviously the library is present in my bower_components folder.
Note: webpack version 2.2.1
And this is my package.json:
{
"name": "TeamcenterEasyApp-0.0.1",
"version": "1.0.0",
"description": "",
"main": "entry-point.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"webpack": "^3.8.1"
}
}

Resources