Level / classic-level

An abstract-level database backed by LevelDB.
MIT License
57 stars 10 forks source link

Broken in Stackblitz with `Error: Cannot load native addon because loading addons is disabled: .../node.napi.glibc.node` #92

Closed seveibar closed 2 weeks ago

seveibar commented 2 weeks ago

Hi everyone,

I didn't see anything on the web about this issue, but it seems like classic-level doesn't work in the Stackblitz environment (many modules don't!)

What's the solution here? Would love a workaround!

image

vweevers commented 2 weeks ago

Currently, WebContainers can only execute languages that are natively supported on the Web, including JavaScript and WebAssembly. It is not possible to run native addons which are usually implemented using native languages such as C++, unless they can be compiled to WebAssembly. Therefore, loading native addons is disabled by default via --no-addons in WebContainers. As a result, you may encounter an error that says: Cannot load native addon because loading addons is disabled.

The solution to this is to use an alternative to the native addon which is either fully implemented in JavaScript or can be compiled to WebAssembly. — https://developer.stackblitz.com/platform/webcontainers/troubleshooting-webcontainers

TLDR, it's simply not supported.

seveibar commented 2 weeks ago

@vweevers I was thinking of writing a levels module that could work in these environments- I saw that some people have done this in the past but they are a bit dated. Curious if there's a "popular" way to use levels in NodeJS without native addons.

seveibar commented 2 weeks ago

Maybe this issue doesn't belong on this repo too since it's definitely not something I think classic-levels should add support for (I think?), but I did want to help with the SEO to direct people (if there is a common alternative)

mcollina commented 2 weeks ago

doesn't work in the Stackblitz environment

Stackblitz is a fork of Node.js, not Node.js itself.

seveibar commented 2 weeks ago

@mcollina do you think anyone cares about using level in environments that don't support native/c addons? I have no idea if it's common. I can understand that "if you don't support native addons you kind of aren't NodeJS- it's an issue for stackblitz etc."

(fwiw I'm also ok w/ closing this issue/seeing if other people stumble on it over time?)

I ended up using memory-level because persistence wasn't super important for my app.

vweevers commented 2 weeks ago

I don't know if StackBlitz provides access to web APIs like IndexedDB but if they do then browser-level is probably the best option, if you do need persistence. An alternative is https://github.com/Level/community/issues/63.

In any case, we can't add support for StackBlitz in classic-level because this module is specifically for Node.js.