Cannot use flow-js-sdk/fcl with Rollup or Vite bundlers
See original GitHub issueFCL, and its use fo grpc, relies on built-in node functions that are not usable in browser. These are currently polyfilled by webpack (I’ve heard this behaviour will going forward) but other bundlers do not work.
Solution: Don’t use grpc, or other node only stuff, for browser fcl.
I understand this is plan. If FCL didn’t rely on node then it would run freely in browser. Best option.
Solution: Figure out how to polyfill/shim node functions with Rollup/Vite.
In the mean time, I have not been able to get this working… maybe I’m missing something that should make this easier.
I have tried rollup-plugin-polyfill-node and @rollup/plugin-commonjs.
These alias:
vite: {
resolve: {
alias: {
process: 'process/browser',
stream: 'stream-browserify',
zlib: 'browserify-zlib',
util: 'util',
http: 'http-browserify',
https: 'https-browserify',
'node-fetch': 'isomorphic-fetch',
'process.env': 'import.meta.env',
Shims
import { Buffer } from 'buffer'
import process from 'process'
import EventEmitter from 'events'
import queueMicrotask from 'queue-microtask'
import url from 'url'
(window as any).global = window
window.Buffer = Buffer
window.EventEmitter = EventEmitter
window.process = process
window.queueMicrotask = queueMicrotask
window.url = url
These seems to cover most things but I’m still getting errors in grpc’s use of http/https libraries.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Why Vite
Vite pre-bundles dependencies using esbuild. esbuild is written in Go and pre-bundles dependencies 10-100x faster than JavaScript-based bundlers.
Read more >Build Options - Vite
rollupOptions. Directly customize the underlying Rollup bundle. This is the same as options that can be exported from a Rollup config file and...
Read more >Comparisons with Other No-Bundler Solutions - Vite
Vite uses esbuild instead of Rollup for dependency pre-bundling. This results in significant performance improvements in terms of cold server start and re- ......
Read more >Troubleshooting - Vite
Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js' #. The path to your project folder may include & , which doesn't work with npm on Windows ......
Read more >Comparisons | Vite
If you are using Preact, WMR is likely going to offer a more fine-tuned experience. ... manually setting up a Rollup configuration for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Still happening on latest release
We also have this issue (Vue with Vite), and I’ve managed to bundle it and republished a package we consume internally here: https://github.com/samatechtw/onflow-fcl-esm
@muttoni You might be able to get some ideas from the rollup config there. It also includes (incomplete) typings, but I wouldn’t recommend using it in production yet.