我正在开发一个带有角2的电子应用程序。
我遵循这教程来初步设置环境。
我的设置有点复杂,但总的来说是非常相似的。
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"app/node_modules",
"dist"
]
}systemjs.config.js和index.html一样,在教程中也是如此
我的一个模块(位于app文件夹中的某个地方-- app/*/*/*/module)依赖于node-ffi。因此,我向typings.json添加了必要的类型:
{
"globalDependencies": {
"core-js": "registry:dt/core-js",
"jasmine": "registry:dt/jasmine",
"node": "registry:dt/node",
"ref": "registry:dt/ref",
"ref-struct": "registry:dt/ref-struct",
"ffi": "registry:dt/node-ffi"
}
}现在,模块试图像这样使用ffi:
import { DynamicLibrary, Library, types } from 'ffi';
export class CppProxy {
//Some code
}它最终被转移到:
var ffi_1 = require('ffi');
//Utilize ffi_1 exported stuff根据这的文章,有一种定义良好的node.js模块查找方法,根据这种方式,它应该找到node-ffi模块,因为node-ffi驻留在app/node_modules中。但是,它没有,它只在app文件夹中查找ffi.js,显然找不到它。
我第一次修复它的尝试是将ffi条目添加到systemjs.config.js的map部分,如下所示:
var map = {
'app': '.', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'node-binary': 'node_modules/systemjs-plugin-node-binary/node-binary.js',
'ffi': 'node_modules/ffi/lib/ffi.js'
};它帮助加载ffi,但也带来了新的问题。ffi本身依赖于其他模块:
var ref = require('ref')
var assert = require('assert')
var debug = require('debug')('ffi:ffi')
var Struct = require('ref-struct')
var bindings = require('./bindings')所以现在应用程序找不到这些模块。我也尝试将其中的一些添加到映射中,但它还是解决了一个级别的依赖关系。
对我来说,这似乎不对,require不应该只查看app文件夹,我不想递归地将所有依赖项添加到systemjs.config.js的映射部分。我做错了什么?
Upd:
还有一个问题处理一个非常类似的问题,但它专门要求使用require('remote')。
我在问如何使用Node.js模块解析机制,同时仍然使用System.js作为模块加载器。
https://stackoverflow.com/questions/38747445
复制相似问题