Using electron in combination with Angular2, Typescript and Electron I am try to find out how to use a node module package installed via npm.
The current problem is that I have to specify the location of the module like var module = require('./node_modules/xyz/lib/xyz.js')
. But then electron does not find the dependencies of xyz, which are located within ./node_modules/xyz/node_modules/yyy
and complains ./yyy.js
can not be found.
The electron app structure
dist
├── angular2.dev.js
├── config.js
├── index.html
├── main.js
├── node_modules
├── package.json
└── app.js
The node-pre-gyp tool provides a way to deploy native Node modules with prebuilt binaries, and many popular modules are using it. Sometimes those modules work fine under Electron, but when there are no Electron-specific binaries available, you'll need to build from source.
fetch API. Runs on both Electron and Node. js, using either Electron's net module, or Node. js http module as backend.
You can use patch-package to make and persist changes to node modules. This can be done by first making changes to the package inside node_modules and then running the following command, with <package name> being the name of the package you just made changes to.
UPDATE:
A similar question has been asked and my answer would most probably help you here:
If you don't append the path to your app node_modules
directory under your app root to the NODE_PATH
variable it is not going to work. So you need to do something like this:
export NODE_PATH=/PATH/TO/APP/node_modules
electron /PATH/TO/APP
When exporting NODE_PATH
make sure that you provide an absolute path.
require
them normally, it's a sign that your package.json
doesn't contain the modules as dependency even if the module is already available under your dist
directory.
So make sure that you are inside dist
directory and use
npm install --save xyz
note the --save
flag!
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