How to make an installer for your electron app - javascript

So I'm trying to make an installer from the end of this video https://www.youtube.com/watch?v=TnXz_nnQZrw for my electron app but I get an error and it doesn't help me at all
Here is my package.json
{
"name": "second-electron-attempt",
"productName": "CPU Monitoring",
"version": "1.0.2",
"description": "A great cpu monitoring tool",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\"",
"build-installer": "electron-builder"
},
"build": {
"appId": "com.nickos.app",
"win": {
"target": "NSIS",
"icon": "src/fraggaros.png",
"requestedExecutionLevel": "requireAdministrator"
},
"nsis": {
"installerIcon": "src/fraggaros.png",
"uninstallerIcon": "src/fraggaros.png",
"uninstallDisplayName": "CPU Monitor",
"license": "license.txt",
"oneClick": false,
"allowToChangeInstallationDirectory": true
}
},
"keywords": [],
"author": {
"name": "NickVelos420",
"email": "velosn#gmail.com"
},
"license": "MIT",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "second_electron_attempt"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"os-utils": "0.0.14"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "12.0.2",
"electron-builder": "^22.10.5"
}
}
And this is the error
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! second-electron-attempt#1.0.2 build-installer: `electron-builder`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the second-electron-attempt#1.0.2 build-installer script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
It says that there is additional logging above but this is what is above
https://i.stack.imgur.com/ruXXC.png
If anyone knows please answer with some code or a great tutorial. btw I've searched on google but there is nothing that tells you how to make an installer for electron. Thank you!

Related

Why does vercel not import libraries?

I tried to create a site in Vercel for my project (link), but for some reason it returned the following error:
Error: Runtime exited with error: exit status 1 Runtime.ExitError
ERROR Cannot find module 'dotenv' Require stack: -/var/task/index.js
ERROR Did you forget to add it to "dependencies" in package.json?
I tried to delete the first line of code from index.js, which requires the dotenv library, since I don't really need it in vercel, but it gives an error when importing express, so I want to know how to solve this problem.
Below is the code of package.json and vercel.json (for some reason I believe the error is in one of these files)
Package.json:
{
"name": "url_saver",
"version": "1.0.0",
"description": "A FCC project",
"main": "index.js",
"engines": {
"node": "14.x"
},
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "~4.18.1",
"mongoose": "~6.6.2",
"dotenv": "~16.0.3",
"dns": "~0.2.2",
"url": "~0.11.0",
"open": "~8.4.0"
},
"keywords": [
"node",
"express",
"freecodecamp",
"mongoose"
],
"license": "MIT",
"author": "Samuel Schlemper"
}
Vercel.json:
{
"version": 2,
"builds": [
{
"src": "./index.js",
"use": "#vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}
Link to full repository on github: https://github.com/Samuel-Schlemper-Schlemuel/Save_URL

Why isn't electron builder returning a .pkg file?

so I'll keep it short. I've been following this tutorial: https://www.techandstartup.org/tutorials/release-electron-app-on-mac-app-store
However as you'll see we need a pkg file to be uploaded to Transporter for App Store Connect. But when I run 'electron-builder' command I only get an 'Application' .I don't get any .dmg files or .pkg file. This is how my .plis looks like `
{
"name": "APPP",
"productName": "APPP",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder --mac"
},
"keywords": [],
"author": {
"name": "ME",
"email": "ME#gmail.com"
},
"license": "MIT",
"devDependencies": {
"electron": "^17.1.2",
"electron-builder": "^22.14.13",
"electron-packager": "^15.5.1"
},
"build": {
"appId": "com.APP",
"productName": "Frost",
"buildVersion": "1.0.0",
"copyright": "Copyright © 2022 Developer or Company Name",
"mac": {
"category": "public.app-category.Productivity",
"icon": "/Users/alex/frost/src/icon.icns",
"target": "dmg",
"hardenedRuntime": false,
"entitlements": "/Users/alex/frost/entitlements.mas.plist",
"entitlementsInherit": "/Users/alex/frost/entitlements.mas.inherit.plist",
"provisioningProfile": "/Users/alex/frost/AppleDevelopment.provisionprofile",
"type": "development"
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
}
}
`

Electron application in production throw: error Command failed: node index.js but in development works fine

Have you ever had this issue:
I was working on my app in development, and everything works fine, but when I created the executable and try to click on my button throw this error:
This the code that is executed when I press my button:
const { exec } = require("child_process");
let myBtn = document.getElementById('my-btn');
myBtn.addEventListener('click', (e) => {
e.preventDefault();
exec("node index.js", (error, data, getter) => {
if(error){
console.log("error",error.message);
return;
}
if(getter){
console.log("data",data);
return;
}
console.log("data",data);
});
});
This the error:
Not recognize the module node and my file index.js
error Command failed: node index.js
internal/modules/cjs/loader.js:1068
throw err;
^
Error: Cannot find module '/home/myUser/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1065:15)
at Function.Module._load (internal/modules/cjs/loader.js:911:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
This is my package.json
{
"name": "app",
"version": "1.0.0",
"description": "description",
"main": "main.js",
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"puppeteer": "^9.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.54",
"#electron-forge/maker-deb": "^6.0.0-beta.54",
"#electron-forge/maker-rpm": "^6.0.0-beta.54",
"#electron-forge/maker-squirrel": "^6.0.0-beta.54",
"#electron-forge/maker-zip": "^6.0.0-beta.54",
"electron": "^12.0.5"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": "",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
}
}

npm start not picking up updated package.json

I am writing a node app from scratch, with the following package.json, which is pretty boiler-plate.
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"start": "node server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
I created server.js to look like this:
var http = require("http");
http.createServer((inRequest, inResponse) => {
inResponse.end("Your IP Address is " + inRequest.connection.remoteAddress);
}).listen(9000);
When I started the app using npm start, it worked fine.
Then, I created a new file called server_time.js:
require("http").createServer((inRequest, inResponse) => {
const requestModule = require("request");
requestModule(
"http://worldtimeapi.org/api/timezone/America/New_York",
function (inErr, inResp, inBody) {
inResponse.end(
`Hello from my first Node Web server: ${inBody}`
);
}
);
}).listen(9000);
I changed the following line in my package.json:
"start": "node server_time.js",
However, Node still seems to pick up server.js instead. I tried npm cache verify, npm cache clear --force, rm -rf node_modules, rm package-lock.json, and npm install again, but the problem didn't seem to go away. I even removed package.json and redefined it, but the value of start when I call npm start is still stale.
Here's an output from my shell:
GsMacbookPro:MyFirstNodeProject g$ cat package.json
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"start": "node server_time.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "G",
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
GsMacbookPro:MyFirstNodeProject g$ ls
node_modules package-lock.json package.json server.js server_time.js
GsMacbookPro:MyFirstNodeProject g$ npm start
> myfirstnodeproject#1.0.1 start /Users/g/Repos/MyFirstNodeProject
> node server.js
Before someone asks, node version is v10.16.3, and npm version is 6.9.0.
The reason why npm start currently works for you is because npm will default some script values based on package contents.
If there is a server.js file in the root of your package, then npm will default the start command to node server.js.
See here:
npm.js - default values
So your start field inside package.json wasn't actually doing anything because it was not under scripts, which is where it should belong.
The correct approach is to update your package.json so that it looks like the following:
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "index.js",
"scripts": {
"start": "node server_time.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "G",
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
Try:
{
"name": "myfirstnodeproject",
"version": "1.0.1",
"description": "Learning node",
"main": "server_time.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server_time.js"
},
"license": "ISC",
"dependencies": {
"request": "^2.88.2"
}
}
and then npm run start.

electron-builder - only build for mac but set to build mac and win

This is the first time I am building electronjs app so most probably I don't know what I am doing.
I follow the instruction from the github and this.
This is my package.json:
{
"name": "ExampleApp",
"productName": "ExampleApp",
"version": "1.0.0",
"description": "Fun app.",
"license": "MIT",
"repository": "user/repo",
"author": {
"name": "sooon",
"email": "Example#gmail.com",
"url": "Example.com"
},
"build": {
"appId": "com. Example.ExampleApp",
"mac": {
"target": "dmg",
"icon": "build/icon.png"
},
"win": {
"target": "nsis",
"icon": "build/icon.png"
}
},
"scripts": {
"test": "xo",
"start": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder"
},
"dependencies": {
"electron-debug": "^1.0.0",
"jquery": "^3.3.1"
},
"devDependencies": {
"devtron": "^1.1.0",
"electron": "^1.8.2",
"electron-builder": "^19.56.0",
"electron-packager": "^8.7.2",
"xo": "^0.18.0"
},
"xo": {
"envs": [
"node",
"browser"
]
}
}
As you can see I have mac and win in the build script. But when I run:
nom run dist
only DMG file (fully functional) is build. There is not trace of any work with win app. What had I miss out in the setting?
I am building this with my MacBook running on 10.12.6. Is it only you can build for your own platform? Can Mac build for Windows?
Update01
I took out:
"build": {
"appId": "com.sooonism.pipidance",
"mac": {
"target": "dmg",
"icon": "build/icon.png"
},
"win": {
"target": "nsis",
"icon": "build/icon.png"
}
},
from the package.json and it still build ok. That means the build script is located somewhere maybe?
electron-builder defaults to building for the current platform. To build both, you need to do something like this in the "script", to build the mac and the window:
"dist-all": "electron-builder -mw"

Categories

Resources