[Important] Fix for Angular: TypeError: Cannot read property 'call' of undefined at Hash.CipherBase (index.js:7)

Hey everyone, in our efforts to run into errors before you do, there is a quick fix for an issue in Angular that makes it impossible to perform important operations. Here is who is affected:

Framework: Angular
SDK: JS, obviously
Affected operations: Cryptographic operations, a.k.a. everything that requires messing around with private keys, you can still instantiate the SDK and e.g. query for the latest block.

Trouble Causer: We need to use some NodeJS packages that are not optimized for the browser by Angular yet, but apparently it is being worked on for the next angular Release.

Fix for now:

  1. In your project root folder, create a file called patch.js containing the following code:
const fs = require('fs');
const f = 'node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';

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.writeFile(f, result, 'utf8', function (err) {
    if (err) return console.log(err);
  });
});
  1. In your package.json , under scripts add the entry "postinstall": "node patch.js" , example:
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "postinstall": "node patch.js"
  },
  1. Reinstall your project’s dependencies: $ rm -R node_modules && npm install

Thanks a lot to @nduchak.chain for his huge help to troubleshoot this one,

Found more elegant solution from web3js community

1 Like

Indeed more elegant, but your is easier to implement :smiley:

1 Like