NativeScriptException:无法找到模块:“加密”(NativeScriptExce

2019-09-28 01:20发布

我试图运行nativescript的OpenPGP的图书馆利用其加密后,我设法安装和运行它,当我尝试使用它,我有这样的错误

JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
JS: ERROR Error: Uncaught (in promise): Error: com.tns.NativeScriptException: Failed to find module: "crypto", relative to: app/tns_modules/

我的package.json有这么

  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/http": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@mattiasbuelens/web-streams-polyfill": "^0.3.2",
    "address-rfc2822": "^2.0.4",
    "asmcrypto.js": "^2.3.2",
    "asn1.js": "^5.0.1",
    "bn.js": "^4.11.8",
    "browserify-derequire": "^1.0.0",
    "buffer": "^5.2.1",
    "compressjs": "^1.0.3",
    "crypto-js": "^3.1.9-1",
    "elliptic": "^6.4.1",
    "hash.js": "^1.1.7",
    "nativescript-angular": "^7.2.3",
    "nativescript-localstorage": "^2.0.0",
    "nativescript-nodeify": "^0.8.0",
    "nativescript-theme-core": "~1.0.4",
    "node-fetch": "^2.3.0",
    "node-localstorage": "^1.3.1",
    "openpgp": "^4.4.10",
    "reflect-metadata": "~0.1.12",
    "rusha": "^0.8.13",
    "rxjs": "~6.3.0",
    "rxjs-compat": "^6.4.0",
    "tns-core-modules": "^5.4.0-next-2019-03-29-153458-02",
    "web-stream-tools": "0.0.1",
    "zone.js": "~0.8.26"
   }

如果任何人知道的东西,请你能告诉我,如果你知道如何使用本地脚本开放PGP库,将是非常有益的

Answer 1:

您的NPM包不会与NativeScript工作,如果它从节点引擎包的依赖,如crypto的实例。

一种解决方法是使用nativescript-nodeify插件,上板从节点引擎几个包,像支持fscrypto等,



Answer 2:

你可以使用我的openpgp.js v2.5.9,其中包括一些polyfills让openpgp.js上Nativescript工作的叉。 你只需要做npm install github:mohammadrafigh/nativescript-openpgpjs#openpgp2和进口的OpenPGP这样的:

import * as openpgp from "openpgp/dist/openpgp";

我会更新这个回购与OpenPGP的4最新变化,并很快将其发​​布在故宫作为一个单独的包,但现在要确保您使用的openpgp2分支,而不是掌握。



文章来源: NativeScriptException: Failed to find module: “crypto”