問題描述
我在 Electron 中有一個 Angular2 應用程序.現在,我想使用 @pokusew/pcsclite
庫來使用 NFC 功能.該庫使用原生 Node.js 模塊.
I have an Angular2 app inside Electron. Now, I would like to use the @pokusew/pcsclite
library to use NFC functionality. This library uses native Node.js modules.
當我嘗試 require 我的 component.ts 中的庫時,如下所示:
When I try to require the library in my component.ts like this:
declare var pcsclite: any;
var pcsclite = require('../../../node_modules/@pokusew/pcsclite/');
我收到錯誤提示:
錯誤 TS6143:模塊../.."已解析為../../lib/pcsclite.js",但未設置--allowJs".
error TS6143: Module '../..' was resolved to '../../lib/pcsclite.js', but '--allowJs' is not set.
另一方面,如果我嘗試通過 index.html 中的 <script>-Tag 導入庫,則會收到一條錯誤消息:
On the other hand, if I try to import the library via a <script>-Tag in the index.html I get an error that says:
ZoneAwareError 錯誤:找不到綁定文件.試過了:...
ZoneAwareError Error: Could not locate the bindings file. Tried:...
最后,如果我 var pcsclite = require('@pokusew/pcsclite');
在 main.js
中,那么它可以工作,但是我沒有可以從我的 Angular 應用程序中訪問它.
Finally, if I var pcsclite = require('@pokusew/pcsclite');
in the main.js
, then it works, but then I don't have access to it from inside my Angular app.
推薦答案
像這樣在 tsconfig.json
中添加 allowJs
選項:
正如 fabian lauer 所說,還添加了 outDir
選項來指定編譯文件的位置:
Add the allowJs
option in your tsconfig.json
like this:
as fabian lauer said also add outDir
option to specify where your compiled files will be:
{
"compilerOptions": {
"outDir": "./built", <--- add this
"allowJs": true, <--- and this
"target": "es5"
},
"include": [
"./src/**/*"
]
}
這篇關于在 TypeScript 中需要 JavaScript Node.js 模塊(未設置allowJs')的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!