Skip to content

Server Error Cannot read properties of undefined (reading 'console') #1257

Description

@devbipu

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions