Skip to content

"Unexpected token 'export'" when installing #76

@jeroenvanrensen

Description

@jeroenvanrensen

Hello,

When installing absurd-sql in a new Sveltekit project, I get the following error: Unexpected token 'export' from /node_modules/absurd-sql/dist/indexeddb-main-thread.js:66: export { initBackend };.

I hope anyone can help me, thanks in advance!

Steps to reproduce

  1. Create a new Sveltekit project: npm create svelte@latest my-app
  2. Install dependencies and start dev server
  3. Install @jlongster/sql.js and absurd-sql via NPM
  4. Update /src/routes/+page.svelte to:
<script>
    import { initBackend } from 'absurd-sql/dist/indexeddb-main-thread'
    import { onMount } from 'svelte'

    onMount(() => {
        function init() {
            let worker = new Worker(new URL('./index.worker.js', import.meta.url))
            // This is only required because Safari doesn't support nested
            // workers. This installs a handler that will proxy creating web
            // workers through the main thread
            initBackend(worker)
        }

        init()
    })
</script>

<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
  1. Create a file src/routes/index.worker.js with the following code:
import initSqlJs from '@jlongster/sql.js';
import { SQLiteFS } from 'absurd-sql';
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';

async function run() {
  let SQL = await initSqlJs({ locateFile: file => file });
  let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
  SQL.register_for_idb(sqlFS);

  SQL.FS.mkdir('/sql');
  SQL.FS.mount(sqlFS, {}, '/sql');

  const path = '/sql/db.sqlite';
  if (typeof SharedArrayBuffer === 'undefined') {
    let stream = SQL.FS.open(path, 'a+');
    await stream.node.contents.readIfFallback();
    SQL.FS.close(stream);
  }

  let db = new SQL.Database(path, { filename: true });
  // You might want to try `PRAGMA page_size=8192;` too!
  db.exec(`
    PRAGMA journal_mode=MEMORY;
  `);

   // Your code
}
  1. Open the browser

In the browser, I get the error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions