UMD bundle from CDNs (and also downloaded files) should work normally. It should be possible to use Web3 1.0 in browsers with them without requiring any additional packages from NPM or other dependency managers.
When using Web3 version beta 38 and later (probably this versions) from CDN (jsDelivr and also others) or downloading a file with UMD bundle, there will be an error and it will be impossible to use Web3 1.0.
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.umd.min.js"></script>
python3 -m http.server 80 # Python 3
php -S localhost:80 # PHP
Firefox:
TypeError: e is undefined web3.umd.js:1
<anonimno> web3.umd.js:1
<anonimno> web3.umd.js:1
<anonimno> web3.umd.js:1
Chrome:
Uncaught TypeError: Cannot read property 'AbstractWeb3Module' of undefined
at web3.umd.js:1
at web3.umd.js:1
at web3.umd.js:1
(anonymous) @ web3.umd.js:1
(anonymous) @ web3.umd.js:1
(anonymous) @ web3.umd.js:1
Edge:
SCRIPT5007: SCRIPT5007: Unable to get property 'AbstractWeb3Module' of undefined or null reference
web3.umd.min.js (7,1624)
Web3: 1.0.0-beta.41 (and also other versions)
Browsers: Firefox, Chrome, Edge
We are having similar issues that began with beta.38
Unable to subscribe to networkChanged { code: -32601,
message: 'The method eth_networkChanged does not exist/is not available' }
Unable to subscribe to accountsChanged { code: -32601,
message: 'The method eth_accountsChanged does not exist/is not available' }
Locking the version at beta.37 fixes our issues
If possible it would be great that the build process bundled one (minified or not) web3.js file.
We will no longer provide a minified full bundle in the NPM package. It's required to bundle your javascript code with Webpack. This because of performance and security reasons.
A Webpack starter project for the Web3.js lib can be found here.
Why? What performance and security reasons are there?
Many developers don't have Node.js installed so they can't use Webpack. For them, the pre-bundled file would be great.
How do we use web3 1.0 in the browser with latest version?
@EddieOne You have to install Node.js and Webpack, then download Web3 repository and run Webpack.
Yeah, I got all that but still I encounter bugs that should be fixed in the later beta versions. Do we need to rebuild the contracts?
web3.version.api
"0.20.3"
Can someone explain how to compile web3.js for the browser using webpack? I have never worked with webpack and the documentation also doesn't tell us how it works.
Most helpful comment
Why? What performance and security reasons are there?
Many developers don't have Node.js installed so they can't use Webpack. For them, the pre-bundled file would be great.