surrealdb / surrealdb.wasm

A WebAssembly engine for the SurrealDB JavaScript SDK
https://surrealdb.com
Apache License 2.0
112 stars 17 forks source link

Bug: The Development Server (index.html) is not working in 0.8.0 release #53

Closed limcheekin closed 6 months ago

limcheekin commented 6 months ago

Describe the bug

I added the following code to the index.html:

const db = new Surreal();

The Chrome browser console throw the following error:

index.js:463 Uncaught TypeError: Cannot read properties of undefined (reading 'surreal_init')
    at new Surreal (index.js:463:26)
    at index.html:15:15

Appreciate the effort to fix the Development Server code as it is important to developers to learn about surrealdb.wasm.

Steps to reproduce

  1. Run the development server with npm run serve, you first need to build the wasm module before this step.
  2. Add const db = new Surreal(); to index.html.
  3. Access http://localhost:8000 from the Chrome browser, you will see the error I reported in developer console of the chrome.

Expected behaviour

No error reported. The db should instantiate successfully.

SurrealDB version

1.2.0

Contact Details

No response

Is there an existing issue for this?

Code of Conduct

rushmorem commented 6 months ago

I may be missing something. Perhaps @kearfy might be able to understand the issue better but I cannot recreate it. With the following changeset, for example, I can see the record created in the console.

diff --git a/index.html b/index.html
index d13024a..0f59495 100644
--- a/index.html
+++ b/index.html
@@ -11,6 +11,11 @@
                        if (typeof window !== 'undefined') {
                                window.Surreal = Surreal;
                        }
+                       const db = new Surreal();
+                       await db.connect("memory");
+                       await db.use({ namespace: "test", database: "test" });
+                       const created = await db.create("foo");
+                       console.log(created);
                </script>
        </body>
 </html>

How are you actually performing your step 2? What does your index.html look like after that step?

I typically don't do step 2 in index.html. I just do step 1 and 3, and then do step 2 in the console itself.

limcheekin commented 6 months ago

@rushmorem Thanks for quick reponse. Sorry for slow response as I'm just back from vacation 2 days ago.

Step 2 is needed to run the code in the index.html. The code look exactly like the one you shared above.

By the way, I use the following command to build the wasm module:

wasm-pack build --release --target web --out-name index --out-dir ../assets/wasm/surrealdb --no-default-features --features protocol-ws,protocol-http,kv-indxdb,kv-mem,rustls

The same command worked with 0.7.0 release. Did I missed anything?

limcheekin commented 6 months ago

Alright.

It works if I build the surrealdb.wasm with the following command:

npm run build