Hi! I try KVision. It looks like I can build web a...
# kvision
m
Hi! I try KVision. It looks like I can build web application and Electron application on single code base. I downloaded
kvision-examples
and tried
template-electron
. If I run task
runApp
it is absolutely OK and the app works. But if I run task
browserRun
the application starts on local port 3000, but app is not working, in browser's console I see error:
require is not defined
. See screenshot. I don't modify code of example, it is my first checkpoint: run web variant and desktop variant of the app. Could you help me?
r
Hi, Electron gives your application access to both browser and electron API. Your app will not run in the browser if you use electron API because the browser can't support it.
You can create web and electron app with a single code base as long as you are using only browser api.
The
template-electron
application uses electron API, so you can not just run it in the browser.
You need to make the following changes to create an application for both the browser and electron: 1. Remove
kvision-electron
module from
build.gradle.kts
2. Add
implementation(npm("electron", "^15.3.5"))
dependency (this is transitive dependency of the kvision module, so now you need to provide it manually) 3. Fix all compilation errors in the
ElectronApp.kt
(this will remove all electron API usage from your app) 4. Remove (or comment)
webpack.config.d/electron.js
file
You will be able to run both
browserRun
and
runApp
gradle tasks
I've also noticed latest kotlin version disables automatic npm scripts, so Electron is not installed properly. Had to add this to the
build.gradle.kts
to make it work again:
Copy code
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension>().ignoreScripts = false
}
m
Oh, thank you very much. I fixed electron installation by hands (running install.js), so it is helpful advice 🙂 And thank you for explanation how to make it work in webapp