-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Cannot find name 'Buffer'. Can't find module 'net'. #2260
Comments
Hey @RohanKapurDEV, In your angular app you have to whitelist the types for node to allow the web3 typing's to work properly when building through the angular cli or iconic. To fix this you have to add the node typing in your
The latest build works with angular perfectly. I will have a look if i can show a better warning and maybe add some docs for this so people can find the solution quicker. This should solve it though and allow your angular app to build. |
Hey, thanks. That actually worked, but not for long unfortunately. :(
It seems as though now there are several other modules that can't be resolved apparently. Crypto, http, https, os, and stream specifically. I'll research more into these as I wait for a response from someone, hopefully I can figure it out, I'll post and close the issue if I do, until then all suggestions are welcome. Thanks. |
There is a lot of different errors from different packages in that trace, It looks like you may be trying to use node things in a UI app, can you show me your angular service typescript code which throws this error please? Also before that can you delete all your node_modules and reinstall to make sure NPM has not got its knickers in a twist? I literally just set up a boilerplate angular 7 app and used the web3 typing's which is working fine once i do the above steps. |
I just found a fix for this error from your initial bug raised, i will do a PR now and resolve this so it shouldn't happen again, the solution is a temp fix until this PR i create is merged. |
Sure, here is the test service im using:
I basically just inject this service into a component's .ts file and call the test method. That produces the error. |
strange i done exactly that and its just worked. If you try a plain boilerplate angular app without the other packages you have does it work? I am saying this because you get a lot of other errors being thrown which are not related to web3
I think this may be the other packages causing this and if the above works then that is probably the cause. If you want me to have a look @ it please feel welcome to create a repo which i can look at. |
Hey I just made a repo you can take a look at, hopefully you'll spot something I can't. Let me know, and thanks for the continued help. |
I have just done a PR which fixes the first issue you raised - #2261 (you have to use the workaround i stated above until its released)👍 I will take a look at your repo now for you. |
ahhh i think i found your issue, this is a mismatch issue with the angular-cli-files default if you create a file called
then in your run This is because we have to replace the I just did that and boom worked on your repo: I will look further into this and try to find a way we can fix this within the install of Cheers @RohanKapurDEV |
Thanks so much for all the help. Much appreciated! I'll go ahead and close the issue. |
Great i also fixed that |
For future readers, if the above method does not work try this: |
Thanks for this. This issue should never appear again after the next release though. 👍 |
Patch applied as suggested in web3/web3.js#2260 (comment) and https://github.com/ChainSafe/web3.js/blob/1.x/README.md
[truncate... se the original post above]
Just in case someone is not finding the file, at this moment I am using Angular 11.2.8 and web3 1.3.5 the line 82 of this file has to be changed from |
how ti fix the same problem in vite |
Facing the same issue as Buffer is not defined in React. |
@moonClimber Hi, thanks for your answer, what if you don't have browser.js in your node_modules --> config folder? Could I just create the browser.js file? What code would I need to add to this file?
|
Expected behavior
Ionic/Angular handles the Web3 import fine and serves project
Actual behavior
I get an error stating that the name 'Buffer' cannot be found and that the 'net' module cannot be found, it then suggests me to install @types/node. After I install it, I get the same error.
Steps to reproduce the behavior
npm install --save web3
npm install --save-dev @types/node
ionic serve -c
and get the error found belowError Logs
Versions
NPM version 6.4.1, NodeJS version 10.13.0, Ionic CLI v4.9.0, Ionic framework v4, @anglular/cli version 7.2.3, web3: ^1.0.0-beta.41
Side notes
I'm using ionic v4 which just released, it uses Angular as the main frontend framework though. I tried installing @types/node as a developer dependency and normally, either way it didn't work. Would be happy to provide more information if requested, or if anyone knows a version of web3 that works with angular, I'd be happy to try that out too.
The text was updated successfully, but these errors were encountered: