0

how can I fix the below web3-related errors for my Angular 14 dapp?

  • I have tried to run npm i crypto, npm i http, etc.
  • These errors occur when I try to run code that attempts to call a function from a smart contract: this.manager = await report.methods.manager().call();
  • I have tried implementing other solutions on StackOverflow and google, but have not been able to successfully fix these errors (e.g., Module not found: Error: Can't resolve 'url' in webpack 5/Angular 14).
  • Here is a screenshot showing that I have tried ipm i url, added the webpack.config.ts file, and the dapp still does not load does to errors: https://i.stack.imgur.com/hePOW.jpg

index.js:561 [webpack-dev-server] ERROR in ../../node_modules/web3-providers-ws/lib/helpers.js 11:12-26
Module not found: Error: Can't resolve 'url' in 'C:\Users\bpha\Angular\node_modules\web3-providers-ws\lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
    - install 'url'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "url": false }
TylerH
  • 20,799
  • 66
  • 75
  • 101
Baccarani
  • 17
  • 1
  • 3
  • I am stuck on the 'url' error, have tried to run 'npm i url' in my terminal, added a webpack.config.js file with code from the below link, and my Angular 14 dapp still runs into errors when trying to run console.log(web3); https://stackoverflow.com/questions/72720744/module-not-found-error-cant-resolve-url-in-webpack-5-angular-14 – Baccarani Aug 25 '22 at 15:50

1 Answers1

2

I was able to fix this issue , you can Try following steps :

  1. npm install -d url
  2. Add entry in tsconfig.json file - "paths":{"url": ["./node_modules/url"]}
  3. try adding all the pending modules in similar fashion using npm i and adding in ts config file.
  4. Rerun npm run build.