cloudflare / cloudflare/workers-sdk

Stripe SDK x Pages => Dynamic require of "util" is not supported

Open
#7,672 8 comments 6 reactions 1 assignee Assigned to @MattieTK View on GitHub
package:wrangler product:pages
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
186

Description

### Which Cloudflare product(s) does this pertain to?

Pages, Workers Runtime, Wrangler

### What versions are you using?

wrangler 3.99.0, node v22.12.0

### What operating system and version are you using?

Mac 15.0.1

### Please provide a link to a minimal reproduction

_No response_

### Describe the Bug

I'm building an app that has frontend part, and backend inside a page worker. When I'm adding stripe as dependency I'm getting this error from running `wrangler pages dev ./dist`

See: https://github.com/cloudflare/workers-sdk/issues/7672#issuecomment-3209509935

```
Uncaught Error: Dynamic require of "util" is not supported
```

I build worker using this esbuild config:

```
esbuild --bundle --sourcemap ./server/index.ts --format=esm --platform=node --outfile=./dist/_worker.js --watch
```

My wrangler config has such compat configuration
```
"compatibility_date": "2024-11-06",
"compatibility_flags": ["nodejs_compat"],
```

What's interesting — the error does not appear in standard worker, only in cf pages _worker.js

### Please provide any relevant error logs

service core:user:app: Uncaught Error: Dynamic require of "util" is not supported

at null. (bundledWorker-0.720856741514531.js:21:9)
at null. (bundledWorker-0.720856741514531.js:24141:17) in
../../node_modules/.pnpm/combined-stream@1.0.8/node_modules/combined-stream/lib/combined_stream.js
at null. (bundledWorker-0.720856741514531.js:3220:50) in __require2
at null. (bundledWorker-0.720856741514531.js:33164:26) in
../../node_modules/.pnpm/form-data@4.0.1/node_modules/form-data/lib/form_data.js
at null. (bundledWorker-0.720856741514531.js:3220:50) in __require2
at null. (bundledWorker-0.720856741514531.js:58175:32)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.