Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unexpected token 'export'" when installing #76

Open
jeroenvanrensen opened this issue Jun 14, 2024 · 0 comments
Open

"Unexpected token 'export'" when installing #76

jeroenvanrensen opened this issue Jun 14, 2024 · 0 comments

Comments

@jeroenvanrensen
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant