Error creating electron executable files for production - javascript

I'm new in Electron and the problem that I have is when I try to create an executable file.
I've tried many exemples and always I have the same problem. The executable file is created but when I try run it, don't work.
Appears the following error in a windows dialog
[Window Title] Error
[Main Instruction] A JavaScript error occurred in the main process
[Content] Uncaught Exception: Error: Unable to find a valid app
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:121:9)
at Object. (D:\Projects\angular\my-electron-app\packages\my-electron-app-1.0.0-win32-ia32\resources\electron.asar\browser\init.js:188:3)
at Module._compile (module.js:642:30)
at Object.Module._extensions..js (module.js:653:10)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Function.Module.runMain (module.js:683:10)
at startup (bootstrap_node.js:196:16)
at bootstrap_node.js:622:3
[OK]
This is my package.json:
{
"name": "my-electron-app",
"version": "1.0.0",
"scripts": {
"start": "concurrently \"ng serve\" \"npm run electron\"",
"electron": "electron ./src/electron.dev",
"ng": "ng",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
...
}
How can I fixed this?

After studied a lot I found the solution, I don't know if it's the best way, but works.
When I was executing the build for my application, in my file "angular.json" had the property outputPath with this way: "outputPath": "dist/my-electron-app", but to generate my windows packge I needed only "dist".
In this way when I execute de command:
"package:win": "npm run build && cross-var electron-packager dist $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite "
it will generate only the folder "app" over my "electron\resources\" with the correct files, before that it generated the folder "app/my-app"
Thanks

Related

vue-cli - cannot build for development mode

I have a .env file in my project
-public
-src
-.env.development.local
package.json
{
"name": "my-website",
"version": "0.1.0",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --mode development",
"lint": "vue-cli-service lint"
}
}
When I run npm run build for the first time, it works.
When I run it after that, it shows error:
my-website#0.1.0 build: `vue-cli-service build --mode development`
When I dig into the logs
13 verbose stack Error: my-website#0.1.0 build: `vue-cli-service build --mode development`
13 verbose stack Exit status 1
After I delete the public folder, it suddenly works
There should be more log output which would be helpfull.
Based on your error maybe this helps:
https://github.com/vuejs/vue-cli/issues/3420
also try deleting your package-lock file and run npm i again
after that it hopefully works
After I update the outputDir from public to build, it works.
vue.config.js
module.exports = {
outputDir : 'build',
}

Unable to run NextJS based node server on AWS EC2 instance

I have tried to run my node server multiple times I am getting this error, for this I tried to delete .next folder and build again after build complete it throws same error. It is running perfectly on my local machine.
`Could not find a valid build in the '${this.distDir}' directory! Try building your app with 'next build' before starting the server
Error: Could not find a valid build in the '/root/only4laughproject/.next' directory! Try building your app with 'next build' before starting the server.
at Server.readBuildId (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:435:23)
at new Server (/root/only4laughproject/node_modules/next-server/dist/server/next-server.js:44:29)
at module.exports (/root/only4laughproject/node_modules/next-server/index.js:4:10)
at module.exports (/root/only4laughproject/node_modules/next/dist/server/next.js:2:161)
at Object.<anonymous> (/root/only4laughproject/server.js:9:13)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
here is my package.json script
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "npm run-script build && cross-env NODE_ENV=production node server.js",
"go": "cross-env NODE_ENV=production node server.js"
}
on doing npm start command it is running next build command before project build finish it starts my server.js that's why this problem occur, I tried next build after build complete I hit node server.js. It resolve my issue.

Module.js failed to load server.js

I made a little project using node.js to do a few things with Discord. It worked when I ran it locally with node server.js and npm start. I decided to put my project online to see if a certain feature worked. When I uploaded it, the main javascript file (server.js) that starts everything wasn't found.
I just want to be clear that Module.js is not something I made, but part of the node.js built in modules. It's the thing that makes the require function what it is.
The error in all it's glory:
module.js:472
throw err;
^
Error: Cannot find module '/var/lib/openshift/583e028e2d52714d2500041/approot/runtime/repo/server.js'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:420:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:535:3
Package.json:
{
"name": "app",
"version": "0.0.1",
"description": "test",
"scripts": {
"start": "node --use_strict server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"main": "server.js",
"keywords": [
"discord",
],
"author": "kert",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"discord.js": "7.0.0"
},
"engines" : {
"node" : "6.9.1"
}
}
Structure of files:
Discord
└─── .git
└─── node_modules
└─── rbservers <-nothing is used in this folder
└─── app.js
└─── package.json
└─── server.js
If anyone can point out what stupid thing I'm forgetting, pray tell.
My cartridge on OpenShift is the 'Node.js Auto-Updating' one.
Apparently, git wasn't staging/committing all the files in order for them to be pushed. I'll have to look around on how to fix this.
Ugh.

Deploying Node/Express App to Heroku/Production -- Babel/ES6 Error

I'm having a lot of trouble deploying to heroku/production with babel(using babel-cli) + es6 javascript. My app is a simple express and node server written in es6 style javascript.
I'm using "babel-cli" (installed via package.json) and a postinstall script inside package.json to precompile my es6 javascript into a "build" folder before starting the server.
The weird thing is that everything compiles smoothly with babel-cli for development, but not for production.
When deploying to production/heroku, the build process gets stuck on the babel command in Makefile and throws an error.
Package.json
{
"name": "messenger-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"clean": "rm -rf build && mkdir build",
"build-server": "babel src --out-dir build",
"build": "npm run clean && npm run build-server",
"postinstall": "make build",
"start": "node ./build/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.9.0",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"request": "^2.72.0"
},
"engines": {
"node": "4.4.5"
},
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-preset-stage-2": "^6.11.0"
}
}
Makefile:
build: clean server_build
clean:
rm -rf build
mkdir -p build
server_build:
babel src --out-dir build
rsync -av --include \*/ --include \*.json --exclude \* ./src/ ./build/
rsync -av --include \*/ --include \*.ejs --exclude \* ./src/ ./build/
.PHONY: build clean
The error:
You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.
Any help would be much appreciated! Setting up server stuff is my worst nemesis! :(
I usually run babel through weback, so I could be wrong here (I don't typically use makefiles), BUT, I would assume you would need to install babel-core in order for it to run correctly? It seems like the error is related to the fact that you just have "babel" installed, which will not work with v6. You need to install its components, which at minimum would require "babel-core."

How do I add a custom script to my package.json file that runs a javascript file?

I want to be able to execute the command script1 in a project directory that will run node script1.js.
script1.js is a file in the same directory. The command needs to be specific to the project directory, meaning that if I send someone else the project folder, they will be able to run the same command.
So far I've tried adding:
"scripts": {
"script1": "node script1.js"
}
to my package.json file but when I try running script1 I get the following output:
zsh: command not found: script1
Does anyone know the steps necessary to add the script mentioned above to the project folder?
*Note: the command can not be added to the bash profile (cannot be a machine specific command)
Please let me know if you need any clarification.
Custom Scripts
npm run-script <custom_script_name>
or
npm run <custom_script_name>
In your example, you would want to run npm run-script script1 or npm run script1.
See https://docs.npmjs.com/cli/run-script
Lifecycle Scripts
Node also allows you to run custom scripts for certain lifecycle events, like after npm install is run. These can be found here.
For example:
"scripts": {
"postinstall": "electron-rebuild",
},
This would run electron-rebuild after a npm install command.
I have created the following, and it's working on my system. Please try this:
package.json:
{
"name": "test app",
"version": "1.0.0",
"scripts": {
"start": "node script1.js"
}
}
script1.js:
console.log('testing')
From your command line run the following command:
npm start
Additional use case
My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.
"scripts": {
"start": "concurrently \"sass --watch ./style/sass:./style/css\" \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
}
Steps are below:
In package.json add:
"bin":{
"script1": "bin/script1.js"
}
Create a bin folder in the project directory and add file runScript1.js with the code:
#! /usr/bin/env node
var shell = require("shelljs");
shell.exec("node step1script.js");
Run npm install shelljs in terminal
Run npm link in terminal
From terminal you can now run script1 which will run node script1.js
Reference: http://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm
Lets say in scripts you want to run 2 commands with a single command:
"scripts":{
"start":"any command",
"singleCommandToRunTwoCommand":"some command here && npm start"
}
Now go to your terminal and run there npm run singleCommandToRunTwoCommand.
Suppose I have this line of scripts in my "package.json"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"export_advertisements": "node export.js advertisements",
"export_homedata": "node export.js homedata",
"export_customdata": "node export.js customdata",
"export_rooms": "node export.js rooms"
},
Now to run the script "export_advertisements", I will simply go to the terminal and type
npm run export_advertisements
Example:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"build_c": "ng build --prod && del \"../../server/front-end/*.*\" /s /q & xcopy /s dist \"../../server/front-end\"",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
As you can see, the script "build_c" is building the angular application, then deletes all old files from a directory, then finally copies the result build files.

Categories

Resources