Skip to content

[workers-utils] Fix compatibility date detection in create-cloudflare#12156

Merged
penalosa merged 1 commit intomainfrom
12155
Jan 27, 2026
Merged

[workers-utils] Fix compatibility date detection in create-cloudflare#12156
penalosa merged 1 commit intomainfrom
12155

Conversation

@irvinebroque
Copy link
Copy Markdown
Contributor

@irvinebroque irvinebroque commented Jan 26, 2026

Fixes #12155.

When running npm create cloudflare@latest, the compatibility date detection was failing and falling back to a hardcoded date (2025-09-27) instead of using the current workerd compatibility date.

Root Cause: module.createRequire() was being called with a directory path (e.g., /path/to/project). Node.js treats this as a filename at that location and starts module resolution from the parent directory (/path/to). This caused getLocalWorkerdCompatibilityDate() to fail to find miniflare in the project's node_modules.

Fix: Append package.json to the project path when calling createRequire(), ensuring module resolution starts from the correct directory.

// Before (broken - looks in parent directory's node_modules)
module.createRequire('/path/to/project')

// After (fixed - looks in project's node_modules)  
module.createRequire('/path/to/project/package.json')

Example output:

npx https://pkg.pr.new/create-cloudflare@12156

...

╭ Configuring your application for Cloudflare Step 2 of 3
│
├ Installing wrangler A command line tool for building Cloudflare Workers
│ installed via `npm install wrangler --save-dev`
│
├ Retrieving current workerd compatibility date
│ compatibility date 2026-01-20

^ correct compat date — versus #12155 shows wrong compat date


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This is an internal bug fix with no user-facing API changes

Open with Devin

…lare

When module.createRequire() receives a directory path, Node.js treats it
as a filename and starts module resolution from the parent directory.
This caused getLocalWorkerdCompatibilityDate() to fail to find miniflare
in the project's node_modules, falling back to a hardcoded date.

Fix by appending 'package.json' to the project path, ensuring module
resolution starts from the correct directory.

Fixes #12155
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: c41e7df

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 26, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12156

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12156

miniflare

npm i https://pkg.pr.new/miniflare@12156

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12156

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12156

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12156

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12156

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12156

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12156

wrangler

npm i https://pkg.pr.new/wrangler@12156

commit: c41e7df

@irvinebroque irvinebroque marked this pull request as ready for review January 26, 2026 19:01
@irvinebroque irvinebroque requested a review from a team as a code owner January 26, 2026 19:01
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional flags.

Open in Devin Review

@petebacondarwin
Copy link
Copy Markdown
Contributor

I just tried using the preview version:

pnpx https://pkg.pr.new/create-cloudflare@12156 --no-auto-update

But I still see:

╭ Configuring your application for Cloudflare Step 2 of 3
│
├ Installing wrangler A command line tool for building Cloudflare Workers
│ installed via `pnpm install wrangler --save-dev`
│
├ Retrieving current workerd compatibility date
│ compatibility date  Could not find workerd date, falling back to 2025-09-27

@petebacondarwin
Copy link
Copy Markdown
Contributor

petebacondarwin commented Jan 26, 2026

I don't think this is the correct fix for create-cloudflare. I think this bug was introduced by #11620 (cc @dario-piotrowicz), where the logic changed from hitting the npm registry to looking for a local copy. I suspect that we are just not able to find a local copy using require but I don't know why yet.

@petebacondarwin
Copy link
Copy Markdown
Contributor

OK so I built it locally and ran it via a direct path to the cli.js file and indeed that does seem to fix it.
So I guess there is just something funny with the preview in this PR.

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jan 26, 2026
@penalosa penalosa merged commit abd2b71 into main Jan 27, 2026
52 of 57 checks passed
@penalosa penalosa deleted the 12155 branch January 27, 2026 12:22
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

npm create cloudflare@latest = > "compatibility_date": "2025-09-27" (OLD)

4 participants