Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ahhh i think i found your issue, this is a mismatch issue with the angular-cli-files default browser.js settings and is something you have to fix to get web3 to work on angular apps. #5368

Closed
araaan12 opened this issue Aug 21, 2022 · 1 comment

Comments

@araaan12
Copy link

ahhh i think i found your issue, this is a mismatch issue with the angular-cli-files default browser.js settings and is something you have to fix to get web3 to work on angular apps.

if you create a file called patch.js in the root of the angular app

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);
    });
});

then in your package.json under scripts add "postinstall": "node patch.js"

run npm install again and then ng build will all work and you shouldn't have anymore issues.

This is because we have to replace the node:false in the /angular-cli-files/models/webpack-configs/browser.js with 'node: {crypto: true, stream: true}' to allow web3 to work with angular (as they enforce node: false.)

I just did that and boom worked on your repo:

image

I will look further into this and try to find a way we can fix this within the install of web3 as its pretty annoying to have to add the above and hard to know how to sort if you not came across it before.

Cheers @RohanKapurDEV

Originally posted by @joshstevens19 in #2260 (comment)

@luu-alex
Copy link
Contributor

luu-alex commented Oct 4, 2022

hey, web3js should work with angular apps now using the 1.8 version. If u find an issue feel free to reopen this

@luu-alex luu-alex closed this as completed Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants