I'm trying to make an electron app. However, my work stuck on very beginning: the require
keyword gives me a string, instead of module object.
electron = require('electron')
console.log(electron)
It prints:
/path/to/my/project/node_modules/[email protected]@electron/dist/electron
, that totally cannot be used as a module.
In comparison, if I import a built-in module, or another npm-installed module:
fs = require('fs')
console.log(fs)
mkdirp = require('mkdirp')
console.log(mkdirp)
It prints object hierarchy, including variables and functions.
The following are contents of election directory, I don't know if they are healthy:
$ ls node_modules/electron
appveyor.yml cli.js CONTRIBUTING.md dist electron.d.ts index.js install.js issue_template.md LICENSE node_modules package.json path.txt README.md test
This is the expected behavior. You need to run your app using electron (in node_modules/.bin), not plain node.
This is what the official tutorial uses inside package.json:
"scripts": {
"start": "electron ."
}
This ends up calling the electron cli, which uses require
to find the path to electron.exe (the string you discovered) and spawns that as a child process that runs the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With