-
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
Angular hack with node: {crypto: true} doesn't work anymore in Angular 12 #4070
Comments
Hi, i spent 2 days on the same issue and found a solution. in the same file: node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js you should add this property in the resolve part (line 51) such as:
once you defined the Secondly, I had other issue to fix such as solution:
in just put I also tried this "cleaner way"
It works now, I probably will find a better way to handle this. (probably we can disable some of the fallback by setting them to false). This problem is caused by webpack 5 not including the node polyfills anymore. this seems to be the reason: NOTE: you will need to edit the browsers.js after each npm i if it reinstall angular, i did this script to do it automagically:
Cheers |
@NicolasKritter Thanks for sharing your solution, I've fixed the There is another solution to provide node polyfills. Instead of modifying tsconfig.json
Of course you still need to install mentioned packages, as you've mentioned above. This makes the solution a bit cleaner. Hope it helps. |
Thanks @dmitry-salnikov This is a better solution as it does not require a dirty fix in the angular installation and is commited I just had to change the pasth from |
Sorry for the delay, we're looking into this, thanks for the report and debugging. |
Thanks, @NicolasKritter & @dmitry-salnikov your solutions worked like charm. I would like to add that one needs to first install the required dependencies using
and thereafter using the solution by @dmitry-salnikov. Now I'm facing the next issue. I'm currently building an Angular 12 based ETH faucet frontend for a private Ethereum blockchain. I can easily connect with e.g. MetaMask using However, whenever I try to execute a contract call I get the following error:
The function I'm executing is the following:
There is no MetaMask popup with the transaction to be signed. What is even more strange, when I call a simple ETH send transaction such as:
the MetaMask pops up here and I can successfully sign the transaction but after that I see the same error about My
and in my
The problem message in the console disappears once I make the following change, but this does not help to get to the MetaMask pop-up:
Does anyone know how to deal with this - I've spent 1 day already debugging without any result. |
Ok guys, after another couple of hours of debugging a finally reached the solution. Solution:
|
Yes it is better to move all the code to polyfills.ts thanks for this findings. Having a quick fix in the index.html bring also some csp problems (need to add the hash of the script) so this best solution is :
|
We're rushing to get hardfork support out + this new webpack issue. Can I ask if someone can verify the output is similar to what was reported in #4090 ? |
@GregTheGreek I didn't check every line but it definitely looks very similar to what I had in the terminal. |
Hi guys, I guess this is still in the works App • ERROR • UI in ./node_modules/eth-lib/lib/bytes.js
Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto
App • ERROR • UI in ./node_modules/web3-eth-accounts/lib/index.js
Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto
App • ERROR • UI in ./node_modules/web3-eth-accounts/node_modules/eth-lib/lib/bytes.js
Module not found: Can't resolve imported dependency "crypto"
Did you forget to install it? You can run: npm install --save crypto
App • ERROR • UI in ./node_modules/web3-providers-http/lib/index.js
Module not found: Can't resolve imported dependency "http"
Did you forget to install it? You can run: npm install --save http
App • ERROR • UI in ./node_modules/web3-providers-http/lib/index.js
Module not found: Can't resolve imported dependency "https"
Did you forget to install it? You can run: npm install --save https
App • ERROR • UI in ./node_modules/xhr2-cookies/dist/xml-http-request.js
Module not found: Can't resolve imported dependency "http"
Did you forget to install it? You can run: npm install --save http
App • ERROR • UI in ./node_modules/xhr2-cookies/dist/xml-http-request.js
Module not found: Can't resolve imported dependency "https"
Did you forget to install it? You can run: npm install --save https
my package.json {
"name": "foobar",
"version": "0.0.1",
"description": "",
"private": true,
"scripts": {
"dev": "quasar dev",
"build": "quasar build",
"lint": "eslint --ext .js,.ts,.vue ./",
"test": "echo \"No test specified\" && exit 0"
},
"dependencies": {
"@quasar/extras": "^1.0.0",
"assert": "^2.0.0",
"axios": "^0.21.1",
"core-js": "^3.6.5",
"crypto": "^1.0.1",
"crypto-browserify": "^3.12.0",
"http": "0.0.1-security",
"https": "^1.0.0",
"https-browserify": "^1.0.0",
"lodash-es": "^4.17.21",
"moment": "^2.29.1",
"moment-timezone": "^0.5.33",
"os": "^0.1.1",
"os-browserify": "^0.3.0",
"pinia": "^2.0.0-alpha.19",
"quasar": "^2.0.0-beta.1",
"stream": "0.0.2",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"vue-clamp": "^0.3.2",
"vue-i18n": "^9.1.6",
"web3": "^1.3.6"
},
"devDependencies": {
"@babel/eslint-parser": "^7.13.14",
"@quasar/app": "^3.0.0-beta.1",
"@types/lodash-es": "^4.17.4",
"@types/node": "^10.17.15",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"axios-mock-adapter": "^1.19.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-vue": "^7.9.0"
},
"browserslist": [
"last 10 Chrome versions",
"last 10 Firefox versions",
"last 4 Edge versions",
"last 7 Safari versions",
"last 8 Android versions",
"last 8 ChromeAndroid versions",
"last 8 FirefoxAndroid versions",
"last 10 iOS versions",
"last 5 Opera versions"
],
"engines": {
"node": ">= 12.22.1",
"npm": ">= 6.13.4",
"yarn": ">= 1.21.1"
}
}
node version |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. If you believe this was a mistake, please comment. |
@GregTheGreek not sure this issue is resolved with the web3.js |
Cc @luu-alex |
@pcaversaccio This issue is not resolved in |
Absolute magic, thank you! |
Any progress on this? I see the above temp fix is working but just wanted to check in. |
Its been a while but we recently picked this issue back up, hopefully we find a more permanent solution for this soon |
this worked on me : |
Thank you all, the web3js README now includes the new instructions to get Angular 12 working with web3js. I'll close this issue for now. |
@luu-alex `An unhandled exception occurred: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
|
Thanks a lot. This is working fine. |
Yepp since 2021 September 30 it is in the web3.js README as well 💚 |
I get the error - file not found node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js |
Angular 12 has migrated to Webpack 5 and made a bunch of other changes to it's build system. Now the fix mentioned in readme - #2260 (comment) - has stopped to work: after modifying
node_modules/@angular-devkit/build-angular/src/webpack/configs/browser.js
by replacingnode: false
withnode: {crypto: true, stream: true}
, build fails with the next error:Seems like some validation was added to browser config.
Could you please take a look for possible workarounds?
Environment
Angular 12.0.0
web3 1.3.6
The text was updated successfully, but these errors were encountered: