jimmywarting / not-a-log

A tiny console interface that returns everything as a string
MIT License
16 stars 0 forks source link

Crashes on import() dynamic import #2

Open JoshuaKGoldberg opened 3 months ago

JoshuaKGoldberg commented 3 months ago

When trying to load the not-a-log module with a dynamic import() expression...

await import("not-a-log").then(mod => mod.default);

...the Proxy attempt to wrap around the 'then' prop and that throws an error:

$ node index.js
file:///Users/josh/repos/repros/node_modules/not-a-log/not-a-log.js:9
    return new Proxy(logger[prop], handler)
           ^

TypeError: Cannot create proxy with a non-object as target or handler
    at Object.get (file:///Users/josh/repos/repros/node_modules/not-a-log/not-a-log.js:9:12)
    at async file:///Users/josh/repos/repros/index.js:1:1

Node.js v22.4.1

I first experienced this trying to run code that imports not-a-log with Vitest: https://github.com/vitest-dev/vitest/issues/6115. @hi-ogawa noted this simpler reproduction in https://github.com/vitest-dev/vitest/issues/6115#issuecomment-2244128356 (thanks again!).

hi-ogawa commented 3 months ago

Just to clarify, there is definitely a bug in Vitest and ideally Vitest should support not-a-log as is.

What I meant is that not-a-log can be potentially made more robust around then (or any other unexpected property access) since that can happen with simple await expression (thought it's understandably odd use usage).