Skip to content

Fails to run on Cloudflare Pages/Workers #3460

Open
@alexcroox

Description

@alexcroox

I was very excited to try this on Cloudflare pages/workers, unfortunately it fails to run with the following:

⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8788
✘ [ERROR] [request error] [unhandled] [GET] http://localhost:8788/health-check

   TypeError: buffer.hasOwnProperty is not a function
      at ../.wrangler/tmp/pages-qV1hY7/chunks/routes/index.get.mjs
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/routes/index.get.mjs:6727:15)
      ... 7 lines matching cause stack trace ...
      at async drainBody
  (file:///Users/alex/Projects/cloudflare-mysql2/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts:5:10)
  {
    cause: TypeError: buffer.hasOwnProperty is not a function
        at ../.wrangler/tmp/pages-qV1hY7/chunks/routes/index.get.mjs
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/routes/index.get.mjs:6727:15)
        at __init
  (file:///Users/alex/Projects/cloudflare-mysql2/dist/.wrangler/tmp/dev-IG5qan/zr2n0f0w3i.js:6:56)
        at null.<anonymous>
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/_/nitro.mjs:3097:28)
        at async Object.handler
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/_/nitro.mjs:2134:19)
        at async toNodeHandle
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/_/nitro.mjs:2405:7)
        at async b
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/_/nitro.mjs:1183:6887)
        at async O
  (file:///Users/alex/Projects/cloudflare-mysql2/.wrangler/tmp/pages-qV1hY7/chunks/_/nitro.mjs:1183:7170)
        at async jsonError
  (file:///Users/alex/Projects/cloudflare-mysql2/node_modules/wrangler/templates/middleware/middleware-miniflare3-json-error.ts:22:10)
        at async drainBody
  (file:///Users/alex/Projects/cloudflare-mysql2/node_modules/wrangler/templates/middleware/middleware-ensure-req-body-drained.ts:5:10),
    statusCode: 500,
    fatal: false,
    unhandled: true,
    statusMessage: undefined,
    data: undefined
  }

I've tracked it down to the safe-buffer dependancy.

mysql2 3.13.0
└─┬ iconv-lite 0.6.3
└── safer-buffer 2.1.2

It looks like this was reported a couple of years ago: ChALkeR/safer-buffer#7

I've narrowed down my project and it only triggers this error when the 'mysql2/promise' is imported.

It runs fine locally with node just not with wrangler locally or on CF remotely. I've tried deploying to both pages and workers with Nitro.js

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions