dahlia/logtape

JSR logtape doesn't work under Node.js

Closed this issue · 1 comments

Even though it is marked as compatible with Node.js on JSR, logtape fails to load under Node.js when incorporated in a project from JSR.

It fails with:

file:///example/node_modules/@jsr/logtape__logtape/logtape/filesink.deno.js:21
  statSync: Deno.statSync,
            ^

ReferenceError: Deno is not defined
    at file:///example/node_modules/@jsr/logtape__logtape/logtape/filesink.deno.js:21:13
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:475:24)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:109:5)

This is because it appears the package is expecting a module substitution with dnt of filesink.deno.js to be filesink.node.js. This way does not work on JSR and the filesink will have to be dynamically imported based on the detection of the runtime environment.

Also, you will run into issues on things like Cloudflare Workers where all dynamically imported modules will be evaluated as part of the bundling process, and the "unsafe" access of the Deno global will also likely cause exceptions. It is better to access the Deno namespace in modules where top level code might be evaluated by accessing like globalThis?.Deno.statSync.

@kitsonk Your fix just released, check it out! https://jsr.io/@logtape/logtape@0.4.1