electronic app has the following package.json:
package.json
"scripts": {
"start": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder"
}
I can read environment variables by running the electron app with npm start.
process.env.JAVA_HOME
the result exists.
However, if I create a distribution of the electronic app with the npm run dist command and then run the distribution app, I cannot read the environment variable.
the result is undefined
How can I read environment variables in distribution of the electronic app?
I'm working on macOS Monterey
Related
I have created a new rails app, after that I have installed bootstrap with cssbundling-rails,
I am now getting an error The asset "application.css" is not present in the asset pipeline. In order to have the application run I need to run the following script
"scripts": { "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules" },
Only after that there is an application file created on assets/builds path.
But I don't want to run this command every time I am updating the css files, I want the server to pick those updates without running the yarn script.
How can I achieve that?
I recently ran into an issue similar to this and the source of the problem was in fact npm and yarn.
A properly configured application using cssbundling-rails should not need to run the command
"scripts": { "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules" },
to get the application to generate the build/application.css
npm known issue
Check your npm version, there is an issue if you are not using npm 7.1+ that basically prevents yarn from setting things up correctly.
Run npm -v and if necessary, upgrade npm with npm install -g npm#latest
If you had to upgrade npm, you will then need to close out your terminal and launch a new one, verify that the npm version is greater than 7.1.
After upgrading, re run rails css:install:bootstrap
And everything should be configured correctly.
Bundle Watcher
From the documentation for cssbundling-rails
"You develop using this approach by running the bundler in watch mode in a terminal with yarn build:css --watch (and your Rails server in another, if you're not using something like puma-dev). You can also use ./bin/dev, which will start both the Rails server and the CSS build watcher (along with a JS build watcher, if you're also using jsbundling-rails)."
So, you can either run yarn build:css --watch from a separate terminal in your rails application or just use the ./bin/dev but either way should resolve the issue you are experience.
I have the following scripts in my electron js app's package.json
"start": "electron .",
"dev": "nodemon --exec electron ."
butI get the following error when I run the app as npm run dev
'electron' is not recognized as an internal or external command, operable program or batch file
and the app crashes. However, when I run it as npm start it runs fine with no issues.
What maybe the issue with nodemon?
You can resolve it by executing electron with npx:
"dev": "nodemon --exec npx electron ."
but this will run a new instance every time you make a change.
Alternatively, you can install electron globally:
npm i -g electron
I'm working with Ubuntu 18.04 and making builds using electron-builder (node.js, react application). Finally I have workable building which makes some zips (win and linux) and deb (linux). When I install the deb, it works well, but when I unzip the builds, I can't run them:
windows version doesn't work via wine
linux version is not executable.
I'm using Ubuntu 18.04, electron 4.0.4, electron-builder 20.38.5.
Here is my package.json
"scripts": {
"dist": "electron-builder --linux --windows",
"postinstall": "electron-builder install-app-deps"
},
"build": {
"appId": "my_app_id",
"extraFiles": [
"assets"
],
"win": {
"target": "zip",
"icon": "assets/icon.png"
},
"linux": {
"target": [
"deb",
"zip"
],
"icon": "assets/icon.icns"
}
}
So, first I run npx webpack to build the app. Then I run npm run dist to make the builds. It creates linux-x64.zip, win32-x64.zip, amd64.deb. But the thing inside the zips doesn't work.
One important note: I got this stuff as a heritage from other developer, and maybe he didn't commit something necessary and maybe all of this staff was just his training solution and doesn't work at all.
Seems like the problem has gone. I don't need the linux zip, deb works fine. And windows zip works well (tested via VirtualBox).
I run electron-packager to make a distributable from my app, but when I start the App.app, no window is shown, only the top menu.
Question: How do I best debug / troubleshoot this?
The app starts a web server and makes a tcp connection to another server. The html for the electron app is served from the local web server.
This is the output when building:
$ npx electron-packager ./ App --overwrite
Packaging app for platform darwin x64 using electron v1.8.4
Wrote new app to /Users/user/www/app/App-darwin-x64
I tried to run the node app manually in package, but got this:
$ cd App-darwin-x64/App.app/Contents/Resources/app/
$ npm start
electron not found
From package.json:
"devDependencies": {
"electron": "^1.8.4",
"electron-packager": "^12.0.1"
},
$ node -v
v8.11.1
You can't run the app like that, you need to run it without the Content/Resources/app, as thats not where its stored. You need to run it from App-darwin-x64/App.app. You also don't call npm-start, as that's only called for running in dev.
Maybe try having a look at some example electron apps with build processes, try electron-vue as that has some good examples
I have an Electron app that compiles fine on Windows using npm run ewin:
"scripts": {
"start": "electron main.js",
"pack": "build",
"ewin": "build --win --ia32 --x64",
"ewinsign": "export CSC_LINK=file:///${HOME}/certificates/certificate.pfx; export CSC_KEY_PASSWORD=\"$( cat ${HOME}/certificates/certificates_pw.txt )\"; npm run clean:win && build --win --ia32 --x64",
},
So I added the ewinsign in an attempt to get it to sign the app.
I based ewinsign on this discussion:
https://discuss.atom.io/t/signing-windows-app-installer/32511
ewinsign fails with this error:
'export' is not recognized as an internal or external command,
operable program or batch file.
I did not really expect it to work because I am running my build on Windows, and bash commands are not typically available on Windows.
Signing Windows apps should be something with a well known solution so I am hesitant to start hacking together my own solution.
In summary:
I am building my app on Windows.
I have my certificate located here: ${HOME}/certificates/certificate.pfx
I have a file with the password located here: ${HOME}/certificates/certificate_pw.txt
I can successfully build unsigned with npm run ewin.
How can I add a ewinsign command that will build a signed Windows app?
I ended up writing a bat script wrapper that sets the environment variables. That was easier to debug because I could add env statement to see what the environment variables were set to.
Here is the script:
set CSC_LINK=file://%USERPROFILE%/certificates/certificate.pfx
set /p CSC_KEY_PASSWORD=<"%USERPROFILE%/certificates/certificates_pw.txt"
npm run ewin
Of particular note is the =< batch syntax to read a file into a variable. and the /p syntax to only read one line.
If you wanted to use that command and try with the windows replacements, you would be looking for the following:
set is the command that you would use to create a windows
environment variable (instead of export)
type is the equivalent of the bash 'cat' for
windows.
What is {HOME} for you? Is that in your "C:\Users\"Your
User Name" directory? If so, you could use
%USERPROFILE% to get that value.
The resulting code would look something like this:
"ewinsign": "set CSC_LINK=file:///%USERPROFILE%/certificates/certificate.pfx; set CSC_KEY_PASSWORD=\"$( type %USERPROFILE%/certificates/certificates_pw.txt )\"; npm run clean:win && build --win --ia32 --x64"
However, I haven't tested that code, so I am not sure if it will work or not.
Now, I haven't code signed with electron-builder, but I would assume that you would use the windows build options to enforce a certificate. This would be setup in the "build" section of your package.json file:
"build":{
"appid":"yourid",
"asar": true,
"forceCodeSigning": true,
"win":{
"target": "...",
"publisherName": "..."
"certificateFile": "...",
"certificatePassword":"...",
"certificateSubjectName":"...",
"certificateSha1":"...",
"signingHashAlgorithms":"..."
}
}
You might have to play around with those values to get something working, but based on the documentation, that is how I would do it. Reference the parent options here