Skip to content

@ringcentral/sdk requires Node.js polyfills to work in browser #281

@yslpn

Description

@yslpn

Problem Description

The @ringcentral/sdk package requires numerous Node.js-specific polyfills to work in browser environments:

  • buffer
  • process
  • crypto-browserify
  • stream-browserify
  • vm-browserify
  • events
  • path-browserify
  • url

This creates the following issues:

  1. Increased bundle size — polyfills add significant code overhead
  2. Complex bundler configuration — requires explicit resolve.fallback and ProvidePlugin setup
  3. Incompatibility with modern runtimes — Edge Functions, Cloudflare Workers, Deno, and other environments do not support Node.js APIs

Current Configuration

Official recommendation from RingCentral (webpack.js):

plugins: [
    // Workaround for Buffer is undefined:
    new webpack.ProvidePlugin({
        Buffer: ['buffer', 'Buffer'],
    }),
    // Workaround for process is undefined:
    new webpack.ProvidePlugin({
        process: 'process/browser',
    }),
],
resolve: {
    fallback: {
        crypto: require.resolve('crypto-browserify'),
        stream: require.resolve('stream-browserify'),
        vm: require.resolve('vm-browserify'),
        process: require.resolve('process/browser'),
        buffer: require.resolve('buffer'),
        events: require.resolve('events'),
        path: require.resolve('path-browserify'),
        url: require.resolve('url'),
    },
},

Proposed Solution

Migrate to browser APIs that work across all modern runtimes:

Node.js API Browser Alternative
Buffer Uint8Array, TextEncoder/TextDecoder
crypto Web Crypto API (crypto.subtle)
process.env Build-time inline substitution
stream ReadableStream/WritableStream (Web Streams API)
events EventTarget
url URL (already available in browsers)
path Simple string operations or remove dependency

Benefits of Migration

  1. Universal compatibility — code will work in browsers, Deno, Cloudflare Workers, Vercel Edge, etc.
  2. Smaller bundle size — no heavy polyfills required
  3. Simplified integration — users don't need to configure their bundler
  4. Standards compliance — Web APIs are W3C/WHATWG standards

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions