Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Error: Can't resolve 'crypto' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jwa'

Tags:

angular6

jwt

I will install jsonwebtoken module in my angular6 project npm i jsonwebtoken. The jsonwebtoken module Dependencies jwa installed, But that index.js file crypto require error Can't resolve 'crypto', But i already install crypto module.

Please help and clear the issue.

My error:

ERROR in ./node_modules/jwa/index.js
Module not found: Error: Can't resolve 'crypto' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jwa'
ERROR in ./node_modules/jws/lib/sign-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'
ERROR in ./node_modules/jws/lib/verify-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'
ERROR in ./node_modules/jws/lib/data-stream.js
Module not found: Error: Can't resolve 'stream' in '/opt/lampp/htdocs/angular-testing-app/node_modules/jws/lib'
like image 620
Jai Kumaresh Avatar asked Sep 27 '18 05:09

Jai Kumaresh


2 Answers

But instead of using a pre-install, I just hand edited `node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js' and changed the lines in that regex:

// old:
node: false,
// new:
node: { crypto: true, stream: true },
like image 87
Kheireddine Azzez Avatar answered Oct 17 '22 17:10

Kheireddine Azzez


I faced the issue same as you and I resolved. You can follow these steps:

  1. Add this file to root directory

patch.js

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. Add this command to package.json file

package.json

{...
  "scripts": {
    "postinstall": "node patch.js",
    ...
  }
}

Reference: https://gist.github.com/niespodd/1fa82da6f8c901d1c33d2fcbb762947d

like image 15
Hieu Nguyen Avatar answered Oct 17 '22 17:10

Hieu Nguyen