How to use node_modules inside Electron

Using an electron in combination with Angular2, Typescript, and Electron, I'm trying to figure out how to use the node module module installed through npm. The current problem is that I have to specify the location of the module, for example var module = require('./node_modules/xyz/lib/xyz.js') . But then the electron does not find xyz dependencies that are within ./node_modules/xyz/node_modules/yyy and complains that ./yyy.js cannot be found.

The structure of the electronic application

 dist ├── angular2.dev.js ├── config.js ├── index.html ├── main.js ├── node_modules ├── package.json └── app.js 
+5
angular typescript electron
Jun 05 '15 at 10:20
source share
3 answers

UPDATE:

A similar question was asked, and my answer will most likely help you here:

If you do not add the node_modules application directory node_modules under your application root to the NODE_PATH variable, it will not 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 you provide an absolute path.




If the electron cannot find the modules when you usually require them, this is a sign that your package.json does not contain modules as a dependency even if the module is already available in your dist directory.

So make sure you are inside the dist directory and use

 npm install --save xyz 

Check out the --save flag!

+3
Jul 28 '15 at 11:16
source share

The current problem is that I have to specify the location of the module, e.g. var module = require ('./node_modules/xyz/lib/xyz.js')

You should be able to do var module = require('xyz'); If you have this place in the relative path ./node_modules/ .... that you talked about.

0
Jun 09 '15 at 0:44
source share

If you did not include modules in your package.json package, it was easiest for me to copy them all to node_modules in your release. This is something like releases > ARCHITECTURE > resources > node_modules

0
Feb 13 '17 at 13:16
source share



All Articles