canvasxyz / okra-js

MIT License
28 stars 2 forks source link

Importing okra-memory in the browser results in class circular dependency error #1

Closed cristiano-belloni closed 1 year ago

cristiano-belloni commented 1 year ago

See reproduction here: https://codesandbox.io/p/sandbox/blissful-sanne-x3tx83?file=%2Fsrc%2FApp.tsx%3A7%2C18

This results in this error (you can open the app in an external window at this url: https://x3tx83-5173.csb.app/):

Uncaught TypeError: Class extends value undefined is not a constructor or null
    at node_modules/abstract-level/abstract-level.js

From a brief search, it looks like it's due to a class circular dependency.

joeltg commented 1 year ago

It looks to me like it might actually be the events package, which memory-level uses but doesn't have as a dependency. Can you try just adding "events": "^3.3.0" to your package.json dependencies and seeing if that works?

cristiano-belloni commented 1 year ago

It looks to me like it might actually be the events package, which memory-level uses but doesn't have as a dependency. Can you try just adding "events": "^3.3.0" to your package.json dependencies and seeing if that works?

That works. I don't see memory-level using events though (this is its only source file). I suppose it's one of its dependencies?

joeltg commented 1 year ago

Yeah, memory-level extends abstract-level which extends EventEmitter here. events is a native module in NodeJS, so there's a gray area around who's responsible for providing the polyfill in the browsers - some bundlers do it automatically, but not Vite.

joeltg commented 1 year ago

I just published v0.2.1 which adds events as a direct dependency.

cristiano-belloni commented 1 year ago

I just published v0.2.1 which adds events as a direct dependency.

Thanks!