3

I'm trying to run in nativescript the openpgp library to use its encryption, after I manage to install and run it when I try to use it I have this error

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/

my package.json there is so

  "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"
   }

if anyone knows of something please could you tell me, and if you know how to use the open pgp library in native script it would be very helpful

2 Answers2

2

Your NPM package will not work with NativeScript if it has dependencies on packages from Node engine, like crypto for instance.

A workaround is to use nativescript-nodeify plugin, which on-boards support for few packages from Node engine, like fs, crypto etc.,

Manoj
  • 21,753
  • 3
  • 20
  • 41
2

You can use my fork of openpgp.js v2.5.9 which includes some polyfills to let openpgp.js work on Nativescript. you just need to do npm install github:mohammadrafigh/nativescript-openpgpjs#openpgp2 and import openpgp like this:

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

I will update this repo with latest changes from openpgp 4 and publish it on npm as a separate package soon, but for now make sure you are using openpgp2 branch and not master.

Mohammad Rafigh
  • 757
  • 9
  • 17