From 1dadf5461ed8a36e5f6d942fc907fd81ad528be3 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Fri, 5 Dec 2025 19:05:23 +0100 Subject: [PATCH] fix: use Web Crypto API for Cloudflare Workers compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - d1.ts: Use global crypto.randomUUID() instead of importing from 'crypto' - sqlite.ts: Use 'node:crypto' import for Node.js compatibility This fixes the Cloudflare Workers deployment error: "The package 'crypto' wasn't found on the file system but is built into node" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- package.json | 2 +- src/storage/d1.ts | 6 +++--- src/storage/sqlite.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 5cc661d..4987aca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/rondevu-server", - "version": "0.2.1", + "version": "0.2.2", "description": "DNS-like WebRTC signaling server with username claiming and service discovery", "main": "dist/index.js", "scripts": { diff --git a/src/storage/d1.ts b/src/storage/d1.ts index 9f0334e..5f94598 100644 --- a/src/storage/d1.ts +++ b/src/storage/d1.ts @@ -1,4 +1,4 @@ -import { randomUUID } from 'crypto'; +// Use Web Crypto API (available globally in Cloudflare Workers) import { Storage, Offer, @@ -402,8 +402,8 @@ export class D1Storage implements Storage { service: Service; indexUuid: string; }> { - const serviceId = randomUUID(); - const indexUuid = randomUUID(); + const serviceId = crypto.randomUUID(); + const indexUuid = crypto.randomUUID(); const now = Date.now(); // Insert service diff --git a/src/storage/sqlite.ts b/src/storage/sqlite.ts index 01bf451..a5eb9ce 100644 --- a/src/storage/sqlite.ts +++ b/src/storage/sqlite.ts @@ -1,5 +1,5 @@ import Database from 'better-sqlite3'; -import { randomUUID } from 'crypto'; +import { randomUUID } from 'node:crypto'; import { Storage, Offer,