debug icon indicating copy to clipboard operation
debug copied to clipboard

`.extend` is undefined in cloudflare workers

Open kravetsone opened this issue 7 months ago • 6 comments

Image

Why browser version doesnt contain .extend method? It easily make package incompatible with the browser/serverless (Related https://github.com/gramiojs/gramio/issues/10)

As a workaround i switch from .extend to just createDebugger('some:1:2:3')

kravetsone avatar May 24 '25 09:05 kravetsone

Which browser? Which version?

How are you using the code?

Qix- avatar May 24 '25 09:05 Qix-

Which browser? Which version?

How are you using the code?

There is no need to mention which browser Debug module has a browser export which misses .extend function (but @types/debug and common js export has it)

About using u can see the referenced commit

kravetsone avatar May 24 '25 12:05 kravetsone

https://github.com/gramiojs/gramio/issues/10

First it is reproduced on serverless environments such as cloudflare workers (which depends on browsers exports because of nature)

This is a fix: https://github.com/gramiojs/gramio/commit/1f0636b5fe8fed275ae10ff661f63b2901f1b665 Just remove .extend usage which works in node/bun and other serverside runtimes but it missed in browser export

kravetsone avatar May 24 '25 12:05 kravetsone

@kravetsone what makes you think the browser version doesn't contain an .extend method?

  1. starts with setup(env) https://github.com/debug-js/debug/blob/master/src/browser.js#L258
  2. common.js only export is this setup factory, which returns createDebug
  3. the createDebug factory places the extend method on the debug factory
import debug from 'debug';
...

declare global {
  interface Window {
    logger: ReturnType<typeof debug>;
  }
}

export default function RouteComponent() {
  window.logger = debug("Root");

...

Image

airtonix avatar Jun 16 '25 01:06 airtonix

@kravetsone what makes you think the browser version doesn't contain an .extend method?

  1. starts with setup(env) https://github.com/debug-js/debug/blob/master/src/browser.js#L258
  2. common.js only export is this setup factory, which returns createDebug
  3. the createDebug factory places the extend method on the debug factory
import debug from 'debug';
...

declare global {
  interface Window {
    logger: ReturnType<typeof debug>;
  }
}

export default function RouteComponent() {
  window.logger = debug("Root");

...

Image

Okay I really miss it

But idk why it didn't exists in cf workers

kravetsone avatar Jun 16 '25 04:06 kravetsone

Ran into this a couple times lately using nitropack to build the worker bundle. If you externalize debug it works fine. Perhaps nitro is mangling it somehow?

mckamyk avatar Aug 13 '25 16:08 mckamyk