1

Importing web3@1.0.0-beta.55 in a stencil+typescript file for a frontend application directly triggers an error, even without using the imported Web3 object whatsoever.

import Web3 from 'web3';

->

TypeError: Cannot read property 'WebSocket' of undefined

This seems expected as Stencil don't use Webpack. Which is the best way to use Web3 1.0 in the browser? Is there a browser-compatible version of it?

  • I'm confused as to why Webpack is related? Web3 1.0 certainly works fine in browsers. (That's probably its main target.) – smarx Jun 17 at 18:41
  • I made this work by forking github.com/NoahZinsmeister/web3-webpacked and adding externals: {'websocket': 'window.WebSocket'} into the webpack config. Are you sure webpack should be compatible with a browser without webpack? Maybe some bundled versions already used webpack? the latest seems to be not really a bundle cdn.jsdelivr.net/npm/web3@1.0.0-beta.55/dist/web3.esm.min.js – pepo Jun 18 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.