question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use flow-js-sdk/fcl with Rollup or Vite bundlers

See original GitHub issue

FCL, 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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
alexmunoz1692commented, Aug 23, 2022

Still happening on latest release

3reactions
samatechtwcommented, Nov 29, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found