Skip to content
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

Run in the browser without a bundler #2475

Closed
lastmjs opened this issue Mar 8, 2019 · 3 comments
Closed

Run in the browser without a bundler #2475

lastmjs opened this issue Mar 8, 2019 · 3 comments

Comments

@lastmjs
Copy link

lastmjs commented Mar 8, 2019

Description

I would like to run web3.js in the browser without using a bundler like rollup, webpack, or parcel. This used to be possible, but it looks like the .min.js distribution has been removed. That's fine I suppose, since there is an esm and a umd build...except that they don't work in the browser. I've been at this for a while, and I'm not inexperienced with modules and build processes. I'm trying to avoid bundlers, and I'm sure there are others like me. I don't think forcing webpack is a good idea, it's useful and a better DX to be able to load the library straight into the browser at times. The esm build has issues with Node.js dependencies that aren't easily ported to the browser. The umd build has issues with some of its dependencies as well...just load it in the browser from a static file server and you'll see what's happening.

Expected behavior

Load a current version of web3.js in the browser without a bundler or complicated build process.

Actual behavior

Can't load a current version of web3.js in the browser without a bundler, it just doesn't work using any of the distribution files.

Steps to reproduce the behavior

Restrict yourself to not using webpack, rollup, parcel, or similar tools, and try to load web3.js into the browser.

Error Logs

Gists

Versions

  • web3.js: latest beta version
  • nodejs: shouldn't matter
  • browser: latest Chromium, shouldn't matter, latest browsers
  • ethereum node: NA
@nivida
Copy link
Contributor

nivida commented Mar 8, 2019

That's fine I suppose, since there is an esm and a umd build...except that they don't work in the browser

I'm always using webpack and I'm bundling the UMD files for the browser and it works without any problems.

The esm build has issues with Node.js dependencies that aren't easily ported to the browser. The umd build has issues with some of its dependencies as well...

Yes, because I'm handling all external dependencies as external which is the correct way to build a library like Web3.
This allows Webpack and other bundlers to do better tree shaking and the user has also the possibility to overwrite specific dependencies Web3.js is using. The ESM build is for ES6 ready environments and NodeJS is currently not ES6 ready. The CJS bundles are for node environments, UMD for browsers, and ESM will be used from tools which are supporting ES6. If you want to test web3 without a bundler then use the CJS bundles in the Node environment and it will work.

@nivida nivida closed this as completed Mar 8, 2019
@lastmjs
Copy link
Author

lastmjs commented Mar 8, 2019 via email

@carsonwah
Copy link

So, ...Is web3.min.js permanantly gone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants