Quantcast
Viewing all articles
Browse latest Browse all 230087

Trying to use Node Module with Ionic 4 & Angular

Hello @Ray02

I did manage to find the issue with this module. It doesn’t have anything to do with the Ionic Framework, but rather how it WLSJS affected when it is used in a browser. I had to edit the actual package itself and inject some code into Angular to allow it to work. To do this dynamically, I made a patch.js file which included the following:

const fs = require('fs');
const path = require('path');
const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
const g = 'node_modules/@whaleshares/wlsjs/lib/auth/';

fs.readFile(f, 'utf8', function (err, data) {
    if (err) {
        return console.log(err);
    }
    var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true, fs: \'empty\'}');

    fs.writeFile(f, result, 'utf8', function (err) {
        if (err) return console.log(err);
    });
});

let logPath = path.join(g, 'index.js');
let logRows = fs.readFileSync(logPath).toString().split('\n');

logRows.unshift('const regeneratorRuntime = require(\'regenerator-runtime\');');
fs.writeFileSync(logPath, logRows.join('\n'));

In english, this is simply requiring a new dependency (Regenerator-Runtime) inside of node_modules/@whaleshares/wlsjs/lib/auth/index.js and editing some Angular settings having to do with Node, Crypto, and Stream. Inside of the package.json, I then set this file to run after npm install like so:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "node patch.js"
  }

It took me a solid week to fix this issue, and I wish I could’ve gotten more assistance from both Ionic and the developers of WLSJS.


Viewing all articles
Browse latest Browse all 230087

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>