Skip to content

@cloudflare/vite-plugin throws buffer.hasOwnProperty is not a function when using mysql2 #8907

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

Closed
avi-turetsky opened this issue Apr 11, 2025 · 4 comments
Assignees
Labels
bug Something that isn't working vite-plugin Relating to the `@cloudflare/vite-plugin` package

Comments

@avi-turetsky
Copy link

Which Cloudflare product(s) does this pertain to?

Vite Plugin

What versions & operating system are you using?

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

Please provide a link to a minimal reproduction

https://github.com/avi-turetsky/mysql2-repro

Describe the Bug

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.

As mentioned on discord, my hunch is this is related to nitrojs/nitro#3170 & unjs/unenv#486

Please provide any relevant error logs

error running /Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js?v=ebcf4a11

TypeError: buffer.hasOwnProperty is not a function
at node_modules/safer-buffer/safer.js (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js:5809:19)
at __require2 (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/chunk-5FUTL2UF.js:10:50)
at node_modules/iconv-lite/lib/index.js (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js:9328:19)
at __require2 (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/chunk-5FUTL2UF.js:10:50)
at node_modules/mysql2/lib/parsers/string.js (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js:9448:17)
at __require2 (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/chunk-5FUTL2UF.js:10:50)
at node_modules/mysql2/lib/packets/packet.js (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js:9589:24)
at __require2 (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/chunk-5FUTL2UF.js:10:50)
at node_modules/mysql2/lib/packet_parser.js (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/mysql2_promise.js:10375:18)
at __require2 (/Users/averyanturetsky/code/repros/mysql2-repro/node_modules/.vite/deps_mysql2_repro/chunk-5FUTL2UF.js:10:50)

@avi-turetsky avi-turetsky added the bug Something that isn't working label Apr 11, 2025
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Apr 11, 2025
@jamesopstad jamesopstad added the vite-plugin Relating to the `@cloudflare/vite-plugin` package label Apr 11, 2025
@jamesopstad jamesopstad moved this from Untriaged to In Progress in workers-sdk Apr 11, 2025
@marbemac
Copy link

marbemac commented Apr 15, 2025

Edit: nvm, also traces back to safer-buffer

👍 seeing this w another package as well (w latest vite plugin and wrangler)

Image

@jamesopstad
Copy link
Contributor

I think the core of the issue is in Vite itself so I've opened an issue there (vitejs/vite#19931). I'll open a PR to Vite if my proposed solution is agreed upon.

@jamesopstad jamesopstad self-assigned this Apr 24, 2025
@jamesopstad
Copy link
Contributor

PR to Vite (vitejs/vite#19940) has been merged and released in version 6.3.4 (https://github.com/vitejs/vite/blob/v6.3.4/packages/vite/CHANGELOG.md#634-2025-04-30).

@github-project-automation github-project-automation bot moved this from In Progress to Done in workers-sdk Apr 30, 2025
@marbemac
Copy link

thanks @jamesopstad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working vite-plugin Relating to the `@cloudflare/vite-plugin` package
Projects
Archived in project
Development

No branches or pull requests

3 participants