如何电子中使用node_modules(原原子壳层) [英] How to use node_modules within electron (formerly atom-shell)
问题描述
在Angular2,打字稿和电子结合使用电子我试图找出如何通过使用安装NPM的节点模块封装。
目前的问题是,我必须指定像模块的位置VAR模块=要求('./ node_modules / XYZ / lib目录/ xyz.js')
。但随后的电子没有找到XYZ的依赖,这是一家位于 ./ node_modules / XYZ / node_modules / YYY
并抱怨 ./ yyy.js
无法找到。
电子应用结构
DIST
├──angular2.dev.js
├──config.js
├──的index.html
├──main.js
├──node_modules
├──的package.json
└──app.js
更新:
如果你不路径追加到您的应用程序 node_modules
您的应用程序根到 NODE_PATH
变量目录下这是行不通的。所以,你需要做这样的事情:
出口NODE_PATH = / PATH / TO / APP / node_modules
电子/ PATH / TO / APP
导出时 NODE_PATH
确保你提供一个绝对路径。
如果电子找不到模块时,
要求
通常他们,那就是你的的package.json
不包含的一个标志模块,依赖均匀如果该模块是你的 DIST
目录下已经可用。因此,请确保你是在 DIST
目录,并使用
NPM安装--save XYZ
请注意在 ! - 保存
标志
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
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.
If electron cannot find modules when you
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!
这篇关于如何电子中使用node_modules(原原子壳层)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!