Cloudflare Pages Functions: process is not defined after successful build

For Workers & Pages, what is the name of the domain?

What is the error message?

Uncaught ReferenceError: process is not defined at functionsWorker-0.5076308457381207.js:142:28

What is the issue or error you’re encountering

Cloudflare Pages Functions deployment fails with process is not defined, even though process is never referenced in my code. My Functions compile and deploy, but the error occurs at runtime in the final bundled output.

What steps have you taken to resolve the issue?

  • Removed all usage of process.env, btoa, Buffer, and Node-related syntax
  • Rewrote JWT generation using Web APIs (crypto.subtle, TextEncoder)
  • Replaced all emojis and non-ASCII characters in code and output
  • Verified no third-party modules or Node imports are being used
  • Confirmed environment variables are accessed via context.env
  • Added minimal wrangler.toml with compatibility_date and pages_build_output_dir
  • Cleaned all files and re-ran builds

What are the steps to reproduce the issue?

  1. Deploy a Cloudflare Pages project with serverless Functions using Web APIs for JWT signing
  2. Use crypto.subtle.importKey() and subtle.sign() with a service account key
  3. Functions compile and upload successfully
  4. Deployment fails with Uncaught ReferenceError: process is not defined from inside the generated functionsWorker-xxxx.js file

Screenshot of the error

Hi,

Thank you for reaching out.

Can you please tell us more about your configuration? Which tool are you currently using? Have you checked the dependencies if they refer to to process somehow? Are you using any specific plugins or custom configuration? In the file functionsWorker-xxxx.js can you please identify where process is referenced?

We look forward to your response.

I’m writing to request support with a deployment issue that continues to affect my Cloudflare Pages project using Pages Functions.

Project Setup:

Platform: Cloudflare Pages
Functions Location: /functions directory
Function Roles:
submit.js handles POST requests and forwards data
checkAvailability.js calls the Google Calendar API and Google Routes API to determine delivery feasibility
sendEmail.js triggers the Resend API to send delivery confirmations

Secrets are passed only via context.env. There is no usage of process.env or Node-style globals.

Configuration:

No frameworks or bundlers (e.g., Vite, Webpack) are used
No third-party dependencies (e.g., googleapis, jsonwebtoken)
All logic uses only Web APIs (fetch, TextEncoder, crypto.subtle, etc.)
I’m not using the Wrangler CLI for deployment; the build is triggered by GitHub → Cloudflare Pages

My wrangler.toml:

toml

CopyEdit

name = "local-delivery"
compatibility_date = "2025-05-25"
pages_build_output_dir = "./"

Issue

The project builds and uploads successfully:

mathematica

CopyEdit

✨ Compiled Worker successfully  
✨ Upload complete!  
✨ Success: Assets published!

However, it fails at the final publish step with the following error:

vbnet

CopyEdit

Error: Failed to publish your Function.  
Got error: Uncaught ReferenceError: process is not defined  
at functionsWorker-0.5076308457381207.js:142:28

Audit Summary:

I have thoroughly reviewed the codebase:

No use of process, process.env, Buffer, require(), or import from Node modules
No third-party libraries
No emojis or non-ASCII characters in code or HTML output
JWT generation uses crypto.subtle APIs with TextEncoder and a safe base64url encoder (using Uint8Array + btoa)

Only one import statement is present, importing a local module:

js

CopyEdit

import { sendEmail } from "./email-flow/sendEmail.js";

I’ve run recursive grep checks and confirmed that no unintended code is present.


Functions Triggered During Failure

Based on testing and logs, the likely trigger is generateJWT() in checkAvailability.js, which uses the following APIs:

crypto.subtle.importKey
crypto.subtle.sign
TextEncoder
Uint8Array to encode JWT

Could you confirm:

  1. Whether Cloudflare’s Pages Functions bundler (esbuild) might be injecting process during internal bundling?
  2. If there’s a way to bypass this or suppress esbuild entirely for Functions?
  3. Whether this is a known issue when using subtle.importKey or btoa() on large payloads?
  4. If migrating this code to a Workers project would avoid the bundling behavior entirely?

I’m happy to provide a stripped version of the project or logs if helpful.

Thanks

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.