I'm novice and can't understand how to use electron-nightly package properly. And I can't find any information about it. But I need electron-nightly due it has support of ESM.
I use typescript 5.1.3
main.ts:
`import { app } from 'electron';`
package.json:
"devDependencies": {
"@types/node": "^20.5.9",
"electron-nightly": "^28.0.0-nightly.20230908",
"typescript": "~5.1.3"
}
tsconfig.json:
{
"compilerOptions": {
"types": [
"node",
"electron-nightly"
],
...
}
Compile from ts to js done without any errors, but if I try to run compiled app by electron . I get error
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\electron\cli.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I tried:
import { app } from 'electron-nightly'but got error:
`File 'c:/WORKSPACE/MyProject/node_modules/electron-nightly/electron.d.ts' is not a module.ts(2306)`
npm i electronandimport { app } from 'electron'but got error of definitions duplicate inelectronandelectron-nightly:
Definitions of the following identifiers conflict with those in another file...
- rename package
electron-nightlyintoelectronin my node_modules folder (please don't laugh so loud I was so desperate :))) but got error:
Error: Cannot find module 'C:\Program Files\nodejs\node_modules\electron\cli.js'
So my questions:
- Should I install
electronpackage withnpm i electronin addition? And how should I bind my code withelectron-nightlyin this case? - Which package should be imported in main.ts? And If it's
electron-nightlyso how to resolve...is not a module.ts? - Further I would package my app with
electron-forge, so would any problems with it?
Thanks!
You probably didn't define in the environment variables the path of the node in your windows.
That's why the nodejs module is not found as the initial error says
Try setting it like this on your windows, run this in the command line.
1 - You don't need to install the electron package separately if you're using electron-nightly.
2 - The "duplicate definitions" error you are experiencing occurs because you are trying to import Electron modules from two different sources: 'electron' and 'electron-nightly'. Only use Electron Nightly
3 - Electron Forge should work fine with Electron Nightly if you have it set up correctly.