Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit ba56fc6

Browse files
joshstevens19nivida
authored andcommitted
fix: patch the angular browser.js to allow {crypto: true, stream: true} (#3136)
1 parent 8ac5c0e commit ba56fc6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/web3/angular-patch.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const fs = require('fs');
2+
const f = '../../node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js';
3+
4+
// This is because we have to replace the `node:false` in the `/angular-cli-files/models/webpack-configs/browser.js`
5+
// with `node: {crypto: true, stream: true}` to allow web3 to work with angular (as they enforce node: false.)
6+
// as explained here - https://github.com/ethereum/web3.js/issues/2260#issuecomment-458519127
7+
if (fs.existsSync(f)) {
8+
fs.readFile(f, 'utf8', function(err, data) {
9+
if (err) {
10+
return console.log(err);
11+
}
12+
var result = data.replace(/node: false/g, 'node: {crypto: true, stream: true}');
13+
fs.writeFile(f, result, 'utf8', function(err) {
14+
if (err) return console.log(err);
15+
});
16+
});
17+
}

packages/web3/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"author": "ethereum.org",
2121
"types": "types/index.d.ts",
2222
"scripts": {
23-
"dtslint": "dtslint types --onlyTestTsNext"
23+
"dtslint": "dtslint types --onlyTestTsNext",
24+
"postinstall": "node angular-patch.js"
2425
},
2526
"authors": [
2627
{

0 commit comments

Comments
 (0)