Skip to content

avi-turetsky/mysql2-repro

Repository files navigation

mysql2 Buffer Polyfill Reproduction

This repository demonstrates the difference between Cloudflare Vite Plugin's Node.js polyfills and Wrangler's polyfills, specifically when running the mysql2 package.

Issue Description

When using the mysql2 package with Cloudflare Workers, there's a notable difference in behavior between:

  • Running with Vite's development server (dev:vite)
  • Running with Wrangler's development server (dev:wrangler)

The key issue manifests as a buffer.hasOwnProperty is not a function error when using Vite's development server, which can be traced back to the safer-buffer package. This error does not occur when using Wrangler's development server.

Prerequisites

  • Node.js (latest LTS version recommended)
  • npm or bun
  • MySQL database credentials

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
    # or
    bun install

Reproduction Steps

  1. Start the Vite development server:

    npm run dev:vite
    # or
    bun run dev:vite

    Then visit http://localhost:5173/db - this will throw the buffer error.

  2. Start the Wrangler development server:

    npm run dev:wrangler
    # or
    bun run dev:wrangler

    Then visit http://localhost:8787/db - this should work correctly.

Expected Behavior

  • Vite dev server (localhost:5173/db): Should throw a buffer.hasOwnProperty is not a function error
  • Wrangler dev server (localhost:8787/db): Should work correctly and connect to the database

Dependencies

  • mysql2: ^3.14.0
  • @cloudflare/vite-plugin: ^1.0.5
  • wrangler: ^4.10.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors