-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Description
Title
console.js
crashes on Cloudflare Workers (NuxtHub deployment)
Description
When deploying a Nuxt 3 project that uses vuedraggable
to [NuxtHub](https://hub.nuxt.com/) (which runs on the Cloudflare Workers runtime), the app crashes with the following error:
Server Error Cannot read properties of undefined (reading 'console')
The issue comes from console.js
inside the package. The current implementation assumes global.console
always exists:
function getConsole() {
if (typeof window !== "undefined") {
return window.console;
}
return global.console; // ❌ breaks on Cloudflare Workers
}
const console = getConsole();
export { console };
On Cloudflare Workers, there is no global.console
, so this throws at runtime.
Suggested fix
A safer approach is to check all possible environments (window
, global
, and the standard console
object) before returning:
function getConsole() {
if (typeof window !== "undefined" && window.console) {
return window.console;
}
if (typeof global !== "undefined" && global.console) {
return global.console;
}
return console; // fallback to built-in console
}
const myConsole = getConsole();
export { myConsole };
Environment
- vuedraggable version: 4.1.0]
- Nuxt version: 4
- Deployment target: NuxtHub (Cloudflare Workers runtime)
Will I create a pull request with the fixing?
Metadata
Metadata
Assignees
Labels
No labels